切换导航栏会导致视图移动

时间:2016-01-19 00:10:44

标签: ios swift uinavigationbar

我使用以下代码切换显示我的工具栏和导航栏:

override func viewDidLoad() {
    super.viewDidLoad() 
     //set up gesutre to recognise tap
    let tapGestureRecognizer = UITapGestureRecognizer(target:self, action:Selector("toggle:"))
    scrollView.userInteractionEnabled = true
    scrollView.addGestureRecognizer(tapGestureRecognizer)
}

 func toggle(sender: AnyObject) {
    navigationController?.setNavigationBarHidden(navigationController?.navigationBarHidden == false, animated: true)
    navigationController?.setToolbarHidden(navigationController?.toolbarHidden == false, animated: true)
}

override func prefersStatusBarHidden() -> Bool {
    return navigationController?.navigationBarHidden == true
}

override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation {
    return UIStatusBarAnimation.Slide
}

我目前在scrollView中有一个图像。动画导航栏时,它会向下滑动图像,当导航栏动画化后,它会向上滑动图像。如何阻止这种情况发生,以便工具栏显示在图像顶部向下滑动?

0 个答案:

没有答案