【问题标题】:Is it ok the below method to decide to use auto layout?下面的方法可以决定使用自动布局吗?
【发布时间】:2012-12-13 07:33:47
【问题描述】:
(BOOL)isSupportAutoLayOut
{
    int version = [[[UIDevice currentDevice].systemVersion substringToIndex:1] intValue];
    if(version == 6)
    {
       return YES;
    }
    return NO;
 }

我想在 iPhone 和 iPad 上支持 iOS 5 和 iOS 6 系统。

它有错误吗?

【问题讨论】:

  • 请参阅stackoverflow.com/a/7848772/1271826 以确定 iOS 版本。而且,顺便说一句,如果您正在检查 iOS 版本,您想检查 iOS 是否大于或等于 6.0 或小于 6.0, 等于 6.0。但正确的解决方案是,如果您的应用支持 6.0 之前的 iOS 版本,则完全关闭自动布局。

标签: ios autolayout


【解决方案1】:

这样使用

-(BOOL)isSupportAutoLayOut
{
    float version = [[[UIDevice currentDevice].systemVersion] floatValue];
    if(version >= 6.0)
    {
       return YES;
    }
    return NO;
}

【讨论】:

    【解决方案2】:

    如果您需要针对 iOS 5 进行部署,则不能使用 Autolayout。如果你这样做了,你会得到一个例外,说设备不支持 iOS 6 之前的 OS 版本中的新 NSLayoutConstraint 类。

    没有办法像您要求的那样有条件地支持自动布局。

    但是,可能 可以从代码、不同的故事板或 nib (.xib) 文件加载,该文件使用基于条件检查的自动布局构建对于 iOS 6(必须有人确认这一点我试过了,它可以工作)。

    【讨论】:

      猜你喜欢
      • 2013-07-31
      • 2017-12-01
      • 1970-01-01
      • 2016-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-19
      • 1970-01-01
      相关资源
      最近更新 更多