久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

iOS/Swift - 向下/向上滾動時隱藏/顯示 UITabBarContr

iOS/Swift - Hide/Show UITabBarController when scrolling down/up(iOS/Swift - 向下/向上滾動時隱藏/顯示 UITabBarController)
本文介紹了iOS/Swift - 向下/向上滾動時隱藏/顯示 UITabBarController的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我對 iOS 開發很陌生.現在,當我向下滾動和向上滾動時,我正試圖隱藏我的標簽欄.我想讓這個動畫像導航欄一樣.對于導航欄,我只需單擊 Attributes Inspector 中的選項.我看到了一些工具欄的例子,但我不能采用它作為標簽欄.

I'm quite new to iOS development. Right now i'm trying to hide my tabbar when I scroll down and when scrolling up the tabbar should appear. I would like to have this animated in the same way like the navigation bar. For the navigation bar I simply clicked the option in the Attributes Inspector. I saw some examples for the toolbar, but I cant adopt it the tabbar.

self.tabBarController?.tabBar.hidden = true 只是隱藏了我的標簽欄,但它不像導航控制器那樣具有動畫效果.

self.tabBarController?.tabBar.hidden = true just hides my tabbar, but its not animated like the navigation controller.

推薦答案

這是我在生產應用程序中實際使用的代碼.

This is code that i'm actually using in a production app.

它在 Swift 中,它還更新 UITabBar.hidden var.

It's in Swift and it also updates UITabBar.hidden var.

func scrollViewWillBeginDragging(scrollView: UIScrollView) {
    if scrollView.panGestureRecognizer.translation(in: scrollView).y < 0{
        changeTabBar(hidden: true, animated: true)
    }
    else{
        changeTabBar(hidden: false, animated: true)
    }
}

你也可以使用其他回調方法:

You can also use the other callback method:

func scrollViewDidScroll(scrollView: UIScrollView) {
    ...
}

但如果您選擇這樣做,那么您必須處理對實際隱藏 tabBar 的輔助方法的多次調用.

but if you choose so, then you must handle multiple calls to the helper method that actually hides the tabBar.

然后你需要添加這個方法來動畫 tabBar 的隱藏/顯示.

And then you need to add this method that animates the hide/show of the tabBar.

func changeTabBar(hidden:Bool, animated: Bool){
    var tabBar = self.tabBarController?.tabBar
    if tabBar!.hidden == hidden{ return }
    let frame = tabBar?.frame
    let offset = (hidden ? (frame?.size.height)! : -(frame?.size.height)!)
    let duration:NSTimeInterval = (animated ? 0.5 : 0.0)
    tabBar?.hidden = false
    if frame != nil
    {
        UIView.animateWithDuration(duration,
            animations: {tabBar!.frame = CGRectOffset(frame!, 0, offset)},
            completion: {
                println($0)
                if $0 {tabBar?.hidden = hidden}
        })
    }
}

更新 Swift 4

func changeTabBar(hidden:Bool, animated: Bool){
    guard let tabBar = self.tabBarController?.tabBar else { return; }
    if tabBar.isHidden == hidden{ return }
    let frame = tabBar.frame
    let offset = hidden ? frame.size.height : -frame.size.height
    let duration:TimeInterval = (animated ? 0.5 : 0.0)
    tabBar.isHidden = false

    UIView.animate(withDuration: duration, animations: {
        tabBar.frame = frame.offsetBy(dx: 0, dy: offset)
    }, completion: { (true) in
        tabBar.isHidden = hidden
    })
}

這篇關于iOS/Swift - 向下/向上滾動時隱藏/顯示 UITabBarController的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

iOS - Using storyboard and autolayout to center the UIScrollView(iOS - 使用故事板和自動布局使 UIScrollView 居中)
get index or tag value from imageview tap gesture(從 imageview 點擊手勢獲取索引或標簽值)
UIScrollView not scrolling regardless of large contentSize(無論內容大小如何,UIScrollView 都不會滾動)
Clean autorotation transitions in a paging UIScrollView(清除分頁 UIScrollView 中的自動旋轉轉換)
UIScrollView zooming with Auto Layout(UIScrollView 使用自動布局縮放)
How to create an image from a UIView / UIScrollView(如何從 UIView/UIScrollView 創建圖像)
主站蜘蛛池模板: 狠狠狠色丁香婷婷综合久久五月 | 成人动漫视频网站 | 日韩欧美在线免费观看视频 | 亚洲欧美在线视频 | 国产成人叼嘿视频在线观看 | 日韩影院一区 | 国产传媒在线观看 | 91精品国产日韩91久久久久久 | 亚洲一区电影 | 日韩在线视频网址 | 国产在线网站 | 亚洲精品一区二区三区在线观看 | 在线观看成人小视频 | 成人免费一区二区三区视频网站 | 久久亚洲国产精品 | 亚洲狠狠爱一区二区三区 | 精品美女在线观看视频在线观看 | 国产一区日韩在线 | 国产精品视频一区二区三 | 91免费观看在线 | 久久久www成人免费无遮挡大片 | 精品久久久久久久久久久久久久 | 久久香蕉网 | 久在线视频播放免费视频 | 中文字幕乱码一区二区三区 | 成人1区2区 | 狠狠操电影| 国产xxx在线观看 | 中文字幕一区二区三区乱码在线 | 欧美日韩一区二区三区在线观看 | 日韩 国产 在线 | 欧美一级片 | 亚洲成人av | 国产一区二区久久 | 成人影院免费视频 | 中文字幕 国产 | 91一区二区 | 日一区二区 | 91成人在线视频 | 天天色天天色 | 欧美精品在线看 |