首页 > 学院 > 开发设计 > 正文

检测手机朝向UIDevice

2019-11-14 18:19:02
字体:
来源:转载
供稿:网友
- (void)viewDidLoad{    [super viewDidLoad];    //检测设备朝向使用UIDevice,beginGeneratingDeviceOrientationNotifications方法向通知中心发送朝向信息    [[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;    }}

附:检测手机版本信息使用的也是UIDevice.

    //获取硬件信息    UIDevice *device=[UIDevice currentDevice];    //输出版本号    NSLog(@"%@",device.systemVersion);

 

 
 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表