获取设备方向

[[UIDevice currentDevice]beginGeneratingDeviceOrientationNotifications];    //建立通知中心

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];


-(void)orientationChanged:(NSNotification *)notification{

UIDeviceOrientation orientation=[[UIDevice currentDevice]orientation];

switch (orientation) {

case UIDeviceOrientationFaceUp:

NSLog(@"设备正面朝上");

break;

case UIDeviceOrientationFaceDown:

NSLog(@"设备正面朝下");

break;

case UIDeviceOrientationPortrait:

NSLog(@"设备处于正常朝向,主屏幕按钮在下方");

break;

case UIDeviceOrientationPortraitUpsideDown:

NSLog(@"设备处于纵向,主屏幕按钮在上方");

break;

case UIDeviceOrientationLandscapeLeft:

NSLog(@"设备侧立,左边朝下");

break;

case UIDeviceOrientationLandscapeRight:

NSLog(@"设备侧立,右边朝下");

break;

default:

break;

}

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容