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];
}
}
iOS 监听横屏竖屏 隐藏状态栏
最新推荐文章于 2023-10-21 22:37:44 发布