// 监听屏幕旋转通知(因为监听的是状态栏的方向变化,所以只有支持横屏的设备才会收到通知)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doRotateAction:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
#pragma mark - 屏幕旋转监听后方法
- (void)doRotateAction:(NSNotification *)notification
{
// 此时根据当前的设备方向来判断是横屏还是竖屏更加准确
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown)
{ // 竖屏
}
else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)
{ // 横屏
}
}
支持横屏的设备才收到监听,并准确判断当前屏幕方向
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。