加载时无法检测方向 -- iPad

3

我经历了许多不同的问题,但出于某种原因,我仍然无法使我的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);
    }
}

有人有其他建议吗?谢谢提前!

你的应用程序是否始终以纵向模式显示,无论设备方向如何? - MusiGenesis
不,我的应用程序可以在任何方向上转动,除了倒置的纵向。 - Adam Storr
1个回答

4

谢谢!我找到了一个更晚的时间来执行这个操作。 - Adam Storr

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接