-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
//开始生成 设备旋转 通知
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
//添加 设备旋转 通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
// 销毁 设备旋转 通知
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIDeviceOrientationDidChangeNotification
object:nil ];
// 结束 设备旋转通知
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
}
/**屏幕旋转的通知回调*/
- (void)orientChange:(NSNotification *)noti {
UIDeviceOrientation orient = [UIDevice currentDevice].orientation;
switch (orient) {
case UIDeviceOrientationPortrait:
NSLog(@"竖直屏幕");
break;
case UIDeviceOrientationLandscapeLeft:
NSLog(@"手机左转");
break;
case UIDeviceOrientationPortraitUpsideDown:
NSLog(@"手机竖直");
break;
case UIDeviceOrientationLandscapeRight:
NSLog(@"手机右转");
break;
case UIDeviceOrientationUnknown:
NSLog(@"未知");
break;
case UIDeviceOrientationFaceUp:
NSLog(@"手机屏幕朝上");
break;
case UIDeviceOrientationFaceDown:
NSLog(@"手机屏幕朝下");
break;
default:
break;
}
}
iOS 手机屏幕旋转
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 导入 : #import <CoreMotion/CoreMotion.h> 增加属性: 初始化: 在真机关闭屏幕...
- 功能需求:看视频时,因为视频页面都是自定义的,这里只是用了第三方的播放控件,为啥播放也不自己写音视频(哎,这块不是...