繁体   English   中英

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

[英]iPad launch orientation when flat on surface

我有以下代码:

 -(void)viewWillAppear:(BOOL)animated {

    UIDeviceOrientation orientation = [[UIDevice currentDevice] UIInterface];

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

 }

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

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

谢谢

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

[[UIApplication sharedApplication] statusBarOrientation]也适用于您无法访问[self interfaceOrientation]的代码中的某个位置

首先,你知道UIViewController的interfaceOrientation属性吗? 看起来你正试图复制它。 如果你真的想这样做,只需订阅设备方向更改通知,检查新方向是否是有效的界面方向(这是一个宏),如果是,则将值存储到某个变量(如lastSeenOrientation)。 然后,您可以随时随地依赖该值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM