关于ios:iOS-监听横屏竖屏-隐藏状态栏

37次阅读

共计 905 个字符,预计需要花费 3 分钟才能阅读完成。

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];
    }
}

正文完
 0