判断手机屏幕旋转方向

来源:互联网 发布:服务端数据为空淘宝 编辑:程序博客网 时间:2024/05/17 09:03

简书地址

判断手机屏幕旋转方向

- (void)viewDidLoad{   [super viewDidLoad];   //设备旋转通知   [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];   [[NSNotificationCenter defaultCenter] addObserver:self                                            selector:@selector(handleDeviceOrientationDidChange:)                                                name:UIDeviceOrientationDidChangeNotification                                              object:nil    ];}- (void)handleDeviceOrientationDidChange:(UIInterfaceOrientation)interfaceOrientation{   UIDevice *device = [UIDevice currentDevice] ;   switch (device.orientation) {       case UIDeviceOrientationFaceUp:            NSLog(@"屏幕朝上平躺");            break;        case UIDeviceOrientationFaceDown:            NSLog(@"屏幕朝下平躺");            break;        case UIDeviceOrientationUnknown:            NSLog(@"未知方向");            break;        case UIDeviceOrientationLandscapeLeft:            NSLog(@"home键在右");            break;        case UIDeviceOrientationLandscapeRight:            NSLog(@"home键在左");            break;        case UIDeviceOrientationPortrait:            NSLog(@"home键在下");            break;        case UIDeviceOrientationPortraitUpsideDown:            NSLog(@"home键在上");            break;        default:            NSLog(@"无法辨识");            break;    }}
0 0