iPad在表面平坦时的发射方向

Ste*_*eve 11 iphone ipad ios

我有以下代码:

 -(void)viewWillAppear:(BOOL)animated {

    UIDeviceOrientation orientation = [[UIDevice currentDevice] UIInterface];

    if(orientation==UIDeviceOrientationLandscapeLeft || orientation==UIDeviceOrientationLandscapeRight) {
        NSLog(@"Device Landscape");
    } else {
        NSLog(@"Device Portrait");
    }

 }
Run Code Online (Sandbox Code Playgroud)

这适用于模拟器和设备,但只有当iPad在表面上不平坦时,例如,如果我将iPad放在桌面上并加载视图,它会说出它的肖像,所以我无法检测到方向视图出现.

在调用viewWillAppear时检测界面方向的最佳方法的任何想法?

谢谢

Cor*_*ger 27

您应该使用[self interfaceOrientation]而不是设备方向.


Kev*_*vin 9

[[UIApplication sharedApplication] statusBarOrientation] 如果您在代码中无法访问的位置,也可以使用 [self interfaceOrientation]