美文网首页
监听硬件旋转方向

监听硬件旋转方向

作者: 路这么长 | 来源:发表于2016-11-17 10:28 被阅读9次
#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;

}

}

相关文章

网友评论

      本文标题:监听硬件旋转方向

      本文链接:https://www.haomeiwen.com/subject/mwddpttx.html