我经历了许多不同的问题,但出于某种原因,我仍然无法使我的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文件中有所有4个方向可用,并且已经设置了shouldAutorotateToInterfaceOrientation。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
interfaceOrientation == UIInterfaceOrientationPortrait);
} else {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
}
有人有其他建议吗?谢谢提前!