I'm having a lot of troubles with the new auto hiding of the status bar in iOS 8.
In my app, I've got a view in which when the user taps once, the navigation bar and the status bar disappear.
When in landscape, the status bar hides by itself and it's fine to me. I only need it in portrait mode.
But the problem is that when the device is landscape and the bar are shown, when the user taps twice to toggle the bar (so showing), and turns the device in portrait mode, the status bar is still hidden.
Basically I need to be able to hide the statusBar without interfere with its natural behavior on iOS 8, so I recap the scenario:
MRW >
(source: mshcdn.com)
I've tried to adjust the statusBar on willRotate, but I made a mess in which the statusBar would be visible when it wasn't supposed to. Code I'm using:
- (BOOL)prefersStatusBarHidden
{
return statusBarHidden;
}
-(void)toggleBars:(UITapGestureRecognizer *)gesture{
CATransition *animation = [CATransition animation];
animation.type = kCATransitionFromBottom;
animation.subtype = kCATransitionFromTop;
animation.duration = .2f;
[animation setTimingFunction:[CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut]];
BOOL toggleNavigationBar = self.navigationController.navigationBarHidden;
[self.navigationController.navigationBar.layer addAnimation:animation forKey:nil];
[self.navigationController setNavigationBarHidden:!toggleNavigationBar animated:YES];
BOOL toggleTabHidden = self.tabBarController.tabBar.hidden;
if(![[[NSUserDefaults standardUserDefaults] objectForKey:@"showTabBar"]isKindOfClass:[NSNull class]]){
if([(NSNumber*)[[NSUserDefaults standardUserDefaults] objectForKey:@"showTabBar"]boolValue])
{
[self.tabBarController.tabBar.layer addAnimation:animation forKey:nil];
[self.tabBarController setHideTabBar:!toggleTabHidden animated:YES];
}
}
statusBarHidden = [UIApplication sharedApplication].statusBarHidden;
[[UIApplication sharedApplication] setStatusBarHidden:!statusBarHidden withAnimation:UIStatusBarAnimationSlide];
[self setNeedsStatusBarAppearanceUpdate];
if (IS_IOS8){
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)){
if (statusBarHidden){
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
}
}
}
I was thinking about setting a flag in which when the statusBar is hidden when in landscape and all the controls are there, on rotation it would trigger the statusBar. With no success, apparently..
Any help highly appreciated.
Swipe down from the top-right corner of your screen to open Control Center. Tap the Portrait Orientation Lock button to make sure that it's off.
On an iPhone without a Home button, swipe down from the top-right corner of the screen instead. Here, tap on the rotation lock icon (which looks like a lock with a circular arrow) to turn it on or off.
Swipe up from the bottom edge of your screen to open Contol Center. Tap the Portrait Orientation Lock button to make sure that it's off.
Swipe up from the bottom of your screen. This will open the Control Center, from which you can enable or disable rotation lock.
Are you using UIViewController-based status bar appearance?
If you implement prefersStatusBarHidden
I assume you are.
Now,
[[UIApplication sharedApplication] setStatusBarHidden:!statusBarHidden withAnimation: UIStatusBarAnimationSlide];
is not supposed to work with UIViewController-based status bar appearance.
You need just to return different value from prefersStatusBarHidden
method and call setNeedsStatusBarAppearanceUpdate
to notify the app that returning value has changed.
So to change statusbar visibility you should just do
@property (nonatomic, assign) BOOL hideStatusBar;
- (BOOL)prefersStatusBarHidden
{
return self.hideStatusBar;
}
- (void)toggleBars:(UITapGestureRecognizer *)gesture
{
... hide navbar and tabbar ...
self.hideStatusBar = ! self.hideStatusBar;
[self setNeedsStatusBarAppearanceUpdate];
}
And that's it!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With