How can I show/hide the status bar on a pageViewController using tap gesture (iOS8 / Swift)

独自空忆成欢 提交于 2019-12-23 10:09:16

问题


Looking through all the solutions given to similar questions, I have been trying to get the statusBar to show/hide with a tap gesture.

I have set View controller-based status bar appearance = NO in the plist.

I have tried the following code in my DataViewController (page view controller) AND in the RootViewController:

let app = UIApplication.sharedApplication()
app.setStatusBarHidden(true, withAnimation: UIStatusBarAnimation.Fade)

and it doesn't work.

This is embedded in a UITabBarController, would that make a difference?

Also, I was able to get the following to hide the statusBar from the RootViewController:

override func prefersStatusBarHidden() -> Bool {
    return true
}

But the DataViewController does not even call this function, and was only able to hide it permanently this way, rather than toggle it on/off.

Any ideas?


回答1:


I have tried it in code, everything works fine for me. Make sure that the View controller-based status bar appearance is Set to NO. And there is no needs to override prefersStatusBarHidden().




回答2:


if you using UIPageViewController then you should use this code in the RootViewController

if you have a navigationController it will hide it too

on ViewDidLoad()

self.navigationController?.hidesBarsOnTap = true

and use this method to hide or show the status Bar based on if the navigationBar is hidden or not

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


来源:https://stackoverflow.com/questions/27032363/how-can-i-show-hide-the-status-bar-on-a-pageviewcontroller-using-tap-gesture-io

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!