iPhone判断设备当前的方向
- 作者: 联合国抬杠队秘书长
- 来源: 51数据库
- 2022-08-17
UIDevice *device = [UIDevice currentDevice];
switch (device.orientation;) {
case UIDeviceOrientationFaceUp:
NSLog(@"螢幕朝上平躺");
break;
case UIDeviceOrientationFaceDown:
NSLog(@"螢幕朝下平躺");
break;
//系統無法判斷目前Device的方向,有可能是斜置
case UIDeviceOrientationUnknown:
NSLog(@"未知方向");
break;
case UIDeviceOrientationLandscapeLeft:
NSLog(@"螢幕向左橫置");
//imgView.transform = CGAffineTransformMakeRotation((CGFloat)(-90 * M_PI / 180.0));
break;
case UIDeviceOrientationLandscapeRight:
NSLog(@"螢幕向右橫置");
//imgView.transform = CGAffineTransformMakeRotation((CGFloat)(90 * M_PI / 180.0));
break;
case UIDeviceOrientationPortrait:
NSLog(@"螢幕直立");
break;
case UIDeviceOrientationPortraitUpsideDown:
NSLog(@"螢幕直立,上下顛倒");
break;
default:
NSLog(@"無法辨識");
break;
}
推荐阅读
