如何隐藏导航栏和工具栏向下滚动? Swift(像myBridge应用程序)
我向下滚动页面时要隐藏工具栏和导航栏。 当我向上滚动时将其返回。 这怎么可能?
我将如何去检测拖动? 我是否使用平移手势,或者这是滚动视图?
试试这个简单的方法:在Swift 3
testing
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) { if(velocity.y>0) { //Code will work without the animation block.I am using animation block incase if you want to set any delay to it. UIView.animate(withDuration: 2.5, delay: 0, options: UIViewAnimationOptions(), animations: { self.navigationController?.setNavigationBarHidden(true, animated: true) self.navigationController?.setToolbarHidden(true, animated: true) print("Hide") }, completion: nil) } else { UIView.animate(withDuration: 2.5, delay: 0, options: UIViewAnimationOptions(), animations: { self.navigationController?.setNavigationBarHidden(false, animated: true) self.navigationController?.setToolbarHidden(false, animated: true) print("Unhide") }, completion: nil) } }
输出: Updated
注意:如果您将此VC中的任何数据传递给另一个embedded了navigationController
VC,您可能需要unhide
NavigationBar
。
你可以尝试self.navigationController?.hidesBarsOnTap = true在viewDidAppear你也可以在滑动时使用隐藏。
很容易做到这一点:
navigationController?.hidesBarsOnSwipe = true
你可以使用这些代码行:
- (void)scrollViewDidScroll: (UIScrollView *)scroll { // UITableView only moves in one direction, y axis CGFloat currentOffset = scroll.contentOffset.y; CGFloat maximumOffset = scroll.contentSize.height - scroll.frame.size.height; // Change 10.0 to adjust the distance from bottom if (maximumOffset - currentOffset <= 10.0) { self.navigationController?.hidden = YES; } else{ self.navigationController?.hidden = NO; } }