Iphone iPad平放在表面时的发射方向
我有以下代码:Iphone iPad平放在表面时的发射方向,iphone,ipad,ios,Iphone,Ipad,Ios,我有以下代码: -(void)viewWillAppear:(BOOL)animated { UIDeviceOrientation orientation = [[UIDevice currentDevice] UIInterface]; if(orientation==UIDeviceOrientationLandscapeLeft || orientation==UIDeviceOrientationLandscapeRight) { NSLog(@"
-(void)viewWillAppear:(BOOL)animated {
UIDeviceOrientation orientation = [[UIDevice currentDevice] UIInterface];
if(orientation==UIDeviceOrientationLandscapeLeft || orientation==UIDeviceOrientationLandscapeRight) {
NSLog(@"Device Landscape");
} else {
NSLog(@"Device Portrait");
}
}
这非常适用于模拟器和设备,但前提是iPad不是平放在表面上,例如,如果我将iPad放在桌子上并加载视图,它会显示其纵向,因此当视图出现时,我无法检测方向
当调用ViewWillDisplay时,有没有关于检测界面方向的最佳方法的想法
谢谢您应该使用
[self interfaceOrientation]
而不是设备方向。首先,您知道UIViewController的interfaceOrientation属性吗?看起来您正在尝试复制它。如果确实要这样做,只需订阅设备方向更改通知,检查新方向是否为有效的接口方向(该方向是一个宏),如果是,则将值存储到某个变量(如lastSeenOrientation)。然后,您可以在任何地方依赖该值。[[UIApplication sharedApplication]statusBarOrientation]
如果您在代码中的某个位置无法访问[self interfaceOrientation]
那么,如果iPad实际上是面朝上的,你想让你的应用程序做什么?他想知道当设备放平时,是横向视图还是纵向视图。我有一个子视图,它显示在不同的位置,这取决于视图是横向视图还是纵向视图。因此,我需要知道视图出现时界面的方向。iOS 12(或8+)中的情况如何?