[英]How can I show/hide the status bar on a pageViewController using tap gesture (iOS8 / Swift)
Looking through all the solutions given to similar questions, I have been trying to get the statusBar
to show/hide with a tap gesture. 通过查看类似问题的所有解决方案,我一直在尝试通过轻击手势显示/隐藏
statusBar
。
I have set View controller-based status bar appearance = NO
in the plist. 我在plist中设置了
View controller-based status bar appearance = NO
。
I have tried the following code in my DataViewController
(page view controller) AND in the RootViewController
: 我在我的
DataViewController
(页面视图控制器)和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? 这是嵌入在
UITabBarController
,会有所作为吗?
Also, I was able to get the following to hide the statusBar from the RootViewController
: 此外,我能够从
RootViewController
获取以下内容来隐藏statusBar:
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. 但是
DataViewController
甚至没有调用这个函数,只能以这种方式永久隐藏它,而不是打开/关闭它。
Any ideas? 有任何想法吗?
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 . 确保
View controller-based status bar appearance
设置为NO 。 And there is no needs to override prefersStatusBarHidden()
. 并且不需要覆盖
prefersStatusBarHidden()
。
if you using UIPageViewController
then you should use this code in the RootViewController
如果您使用
UIPageViewController
那么您应该在RootViewController
使用此代码
if you have a navigationController
it will hide it too 如果你有一个
navigationController
它也会隐藏它
on ViewDidLoad()
在
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 并使用此方法根据是否隐藏
navigationBar
来隐藏或显示状态栏
override func prefersStatusBarHidden() -> Bool {
if self.navigationController?.navigationBarHidden == true {
return true
}
else
{
return false
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.