[英]swift show and hide Navigation Bar
我想創建:不帶導航欄的顯示視圖,如果從頂部> = 100高度到底部的距離滾動,則顯示導航欄。
當從底部滾動時:如果到頂部的距離<= 100高度需要隱藏導航欄我嘗試此操作,但這沒有幫助
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
if(velocity.y>0) {
UIView.animate(withDuration: 2.5, delay: 0, options: UIViewAnimationOptions(), animations: {
self.navigationController?.setNavigationBarHidden(true, animated: true)
}, completion: nil)
} else {
UIView.animate(withDuration: 2.5, delay: 0, options: UIViewAnimationOptions(), animations: {
self.navigationController?.setNavigationBarHidden(false, animated: true)
}, completion: nil)
}
}
您可以使用scrollViewDidScroll
完成所需的功能。 我已經實施並測試過,並且工作正常。
func scrollViewDidScroll(_ scrollView: UIScrollView) {
print("scroll Content : \(scrollView.contentOffset.y)")
if scrollView.contentOffset.y >= 100
{
UIView.animate(withDuration: 2.5, animations: {
self.navigationController?.setNavigationBarHidden(true, animated: true)
})
}
else
{
UIView.animate(withDuration: 2.5, animations: {
self.navigationController?.setNavigationBarHidden(false, animated: true)
})
}
}
在viewDidLoad()中,您可以隱藏導航欄,因此在打開應用程序時會隱藏時間導航欄。
希望這會幫助你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.