iOS 8 - Rotation makes statusBar disappear even in portrait mode after toggling controls

后端 未结 4 982
渐次进展
渐次进展 2021-02-04 05:34

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 th

相关标签:
4条回答
  • 2021-02-04 05:49

    This is the swift (3.0) version of that prefersStatusBarHidden

    override var prefersStatusBarHidden: Bool{
        return false
    }
    

    You just need to add it to your ViewController

    0 讨论(0)
  • 2021-02-04 05:51

    This worked for me:

    - (void)viewWillLayoutSubviews {
        [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
    }
    
    0 讨论(0)
  • 2021-02-04 06:02

    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!

    0 讨论(0)
  • 2021-02-04 06:09
    #pragma mark After and Before Oriantation Change Methods+Delegate
    
    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
    {
        [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
    }
    
    #pragma mark nav
    
    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
        [[UIApplication sharedApplication] setStatusBarHidden:NO];
    }
    

    This is Short and Easy method.

    0 讨论(0)
提交回复
热议问题