1
我正試圖讓我的導航欄隱藏,當我向上滑動並重新出現時向下滑動。我打印功能的作品,但我不知道爲什麼我的導航欄不隱藏。另外我怎樣才能得到頂部是一個圖像和一個標誌隱藏在滑動。 爲什麼我的導航欄不能在滑動時隱藏?
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)
print("Hide")
}, completion: nil)
} else {
UIView.animate(withDuration: 2.5, delay: 0, options: UIViewAnimationOptions(), animations: {
self.navigationController?.setNavigationBarHidden(false, animated: true)
print("Unhide")
}, completion: nil)
}
}
確保self.navigationController不爲零。如果不存在,代碼將無聲無息地失敗。 –
我在哪裏檢查? @DuncanC – Riccardo
更改您的打印語句以讀取'print(「關於隱藏。navigationController = \(self.navigationController)」)' –