【问题标题】:Different user interfaces for landscape and portrait orientations横向和纵向的不同用户界面
【发布时间】:2012-09-26 21:00:37
【问题描述】:

长期以来,我一直没有找到一个好的答案。

是否可以(必须!;)构建不同的用户界面,例如横向和纵向或具有 3.5" 或 4" 显示屏的 iPhone。

就像在代码中所说,这是横向界面,这是纵向界面...

我希望有一个简单的方法。 :)

来自德国慕尼黑的问候

劳伦兹

【问题讨论】:

    标签: ios cocoa-touch interface landscape portrait


    【解决方案1】:

    这就是我的做法。我创建了一个名为configureViewForOrientation: 的函数,它将您要为其设置界面的方向作为参数。

    -(void)configureViewForOrientation:(UIInterfaceOrientation)orientation
    {
        if (UIInterfaceOrientationIsPortrait(orientation))
        {
            //set up portrait interface
        }
    
        else
        { 
            //set up landscape interface
        }
    }
    

    您可以从 viewDidLoad(或您最初设置界面的任何位置)调用此方法,并使用 [UIApplication sharedApplication].statusBarOrientation 为其提供当前方向:

    -(void)viewDidLoad
    {
        [super viewDidLoad];
        [self configureViewForOrientation:[UIApplication sharedApplication].statusBarOrientation];
    }
    

    您也可以在设备旋转时调用它:

    -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    {
        [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
        [self configureViewForOrientation:toInterfaceOrientation];
    }
    

    有几个注意事项(例如,您是否在应用启动时立即检查设备方向),但这应该在大多数情况下都有效。

    【讨论】:

    • 感谢您的回答,您将如何设置界面取决于方向。对不起,这可能很容易,但我对 ios 很陌生。非常感谢任何帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多