【问题标题】:iPhone 5 Auto Layout not CorrectiPhone 5 自动布局不正确
【发布时间】:2012-10-08 08:10:31
【问题描述】:

新的 iPhone 屏幕搞砸了我的应用程序。在 iPhone 3.5 英寸的屏幕上,一切都显得格格不入。我在同一个故事板中有两个不同的视图,我尝试检测并尝试切换故事板视图,但还没有任何效果。我可以得到一些关于如何在启动时切换到正确视图的代码吗?我是将这段代码放在我的主视图控制器中,还是将它放在我的应用程序委托中?

CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
// code for 4-inch screen
} else {
// code for 3.5-inch screen
}

What my views look like http://www.fileden.com/files/2012/6/18/3317719/screenshot7.jpg

【问题讨论】:

    标签: objective-c xcode storyboard iphone-5 autolayout


    【解决方案1】:

    在应用程序委托中为“didFinishLaunchingWithOptions:”中的应用程序初始化它,然后为设备/屏幕尺寸调用正确的 NIB 或 Storyboard。为每个故事板创建不同的故事板,如果您希望在故事板中使用 iOS 6 的自动布局。用这样的东西开始你的 if 语句:

    if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
            if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568.0){
    //iPhone 5 storyboard
    }
    else { 
    // other storyboard here
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-12
      • 2016-06-13
      相关资源
      最近更新 更多