支持横屏的设备才收到监听,并准确判断当前屏幕方向

//  监听屏幕旋转通知(因为监听的是状态栏的方向变化,所以只有支持横屏的设备才会收到通知)
[[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)
    {   // 横屏
        
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 晚上看书太久总让人觉得头顶的灯光太过恍惚,所以忍不住闭了闭眼睛,惦记着手机,发现始终没有收到她的短信。我们是有灵犀...
    一茶月阅读 455评论 0 0
  • 昨天下午,我去机场接老婆。台湾飞上海,一眨眼的功夫就到了,和我从家里去虹桥机场的时间也差不多,就多个三刻钟吧。PK...
    Graceland阅读 16,941评论 32 28