我已经回答了许多不同的问题,但出于某种原因,我仍然无法让我的 iPad 检测负载方向。
似乎最好的方法是检测 statusBarOrientation:
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"View Loads");
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft
|| [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
NSLog(@"This is Landscape");
} else {
NSLog(@"This is Portrait");
}
}
但它总是返回“Portrait”。我的 .plist 和 shouldAutorotateToInterfaceOrientation 设置了所有 4 个方向:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
interfaceOrientation == UIInterfaceOrientationPortrait);
} else {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
}
有没有人有任何其他建议?提前致谢!
最佳答案
iPad 应用程序始终以纵向模式启动,无论设备的实际方向如何(如果设备处于横向状态,它们会立即旋转为横向)。如果您稍后在程序生命周期中使用相同代码检查状态栏方向,您会看到它返回实际方向。
关于objective-c - 无法检测负载方向 - iPad,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10036748/