我经历了许多不同的问题,出于某种原因,我仍然无法让我的 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");
}
}
但它总是返回“肖像”。我的 .plist 和 shouldAutorotateToInterfaceOrientation 设置中有所有 4 个方向可用:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
interfaceOrientation == UIInterfaceOrientationPortrait);
} else {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
}
有人有其他建议吗?提前致谢!