iOS 监听横屏竖屏 隐藏状态栏

BOOL _isFullScreen;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rotated:) name:UIDeviceOrientationDidChangeNotification object:nil];

- (void)rotated:(NSNotification *)notification
{
    UIDevice *dv = notification.object;
    /*
     
     UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight
     */
    if (dv.orientation == UIDeviceOrientationLandscapeLeft ||
        dv.orientation == UIDeviceOrientationLandscapeRight)
    {
        NSLog(@"横屏");
        _isFullScreen = true;
  
    }else if (dv.orientation == UIDeviceOrientationFaceUp ||
         dv.orientation == UIDeviceOrientationFaceDown)
     {
         NSLog(@"face");
     }else{
         NSLog(@"竖屏");
         _isFullScreen = NO;
    }
    [self reloadStatuestBar];
}
- (BOOL)prefersStatusBarHidden
{
    return _isFullScreen;
}
- (void)reloadStatuestBar {
    if ( [self  respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)] ) {
        // go prefersStatusBarHidden
         [self setNeedsStatusBarAppearanceUpdate];
    } else {
        [[UIApplication sharedApplication] setStatusBarHidden:_isFullScreen];
    }
}

你可能感兴趣的