【问题标题】:Different Launch orientations for iPad and iPhone?iPad 和 iPhone 的启动方向不同?
【发布时间】:2012-04-13 08:08:08
【问题描述】:

我正在制作一个通用应用程序,我想知道是否可以将初始方向设置为 iPad 的横向和 iPhone 的纵向?目前,我在 info.plist 文件中设置了 initial interface orientation ,但 iPad 和 iPhone 似乎没有不同的选项。如果无法通过info.plist 文件完成,那么如何以编程方式完成?

【问题讨论】:

标签: iphone ios ipad orientation


【解决方案1】:

您可以使用以下代码以编程方式进行操作 -

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {

        if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
            return YES;
        } 

    }
    else {

        if (interfaceOrientation == UIInterfaceOrientationPortrait) {
            return YES;
        }
    }

return NO;

}

【讨论】:

  • 这不是我正在寻找的解决方案,我的朋友...问题在于启动方向(当 iOS 没有开始方向通知时,所以 shouldAutorotateToInterfaceOrientationnot 调用)。如果您在 appdelegate 中 NSLog 设备方向,您将获得 orientation unknown 的输出!!!
【解决方案2】:

看起来initial interface orientation 属性与supported orientations 冲突。不过,我找到了解决方案 here

【讨论】:

    【解决方案3】:
        UIDevice* thisDevice = [UIDevice currentDevice];
        if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
        {
            [[UIDevice currentDevice] setOrientation: UIInterfaceOrientationLandscapeRight];
        }
        else
        {
            [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
        }
    

    【讨论】:

    • setOrientation 可以让我的应用被拒绝。还是谢谢
    猜你喜欢
    • 2014-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多