#warning当我们关注的东西和布局相关而不是纯粹设备旋转,就使用statusBarOrientation状态条的
//myDevice.orientation获取的方向一般返回的是0就是unknow
// return current device orientation. this will return UIDeviceOrientationUnknown unless device orientation notifications are being generated.
[myDevicebeginGeneratingDeviceOrientationNotifications];
//消息发送中心
NSNotificationCenter*nc = [NSNotificationCenterdefaultCenter];
[ncaddObserver:selfselector:@selector(xuanzhuan)name:UIDeviceOrientationDidChangeNotificationobject:myDevice];
}
#pragma硬件旋转
- (void)xuanzhuan {
UIDevice*myDevice = [UIDevicecurrentDevice];
switch(myDevice.orientation) {
caseUIDeviceOrientationFaceUp:
NSLog(@"屏幕朝上平躺");
break;
caseUIDeviceOrientationFaceDown:
NSLog(@"屏幕朝下平躺");
break;
//系统无法判断目前Device的方向,有可能是斜置
caseUIDeviceOrientationUnknown:
NSLog(@"未知方向");
break;
caseUIDeviceOrientationLandscapeLeft:
NSLog(@"屏幕向左横置");
break;
caseUIDeviceOrientationLandscapeRight:
NSLog(@"屏幕向右横置");
break;
caseUIDeviceOrientationPortrait:
NSLog(@"屏幕直立");
break;
caseUIDeviceOrientationPortraitUpsideDown:
NSLog(@"屏幕直立,上下顛倒");
break;
default:
NSLog(@"无法识别");
break;
}
}
监听硬件旋转方向
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 运用螺旋仪运动模块监听实现,详细demo:https://github.com/oopsr/DeviceOrien...
- 获得当前屏幕方向 self.interfaceOrientation或[[UIApplication shared...