iOS11,Xcode 9.0 报错,Safe Area Layout Guide Before iOS 9.0
升级到Xcode9之后,新建了一个工程,报错:
Safe Area Layout Guide Before iOS 9.0
iOS 7 之后苹果给 UIViewController 引入了 topLayoutGuide 和 bottomLayoutGuide 两个属性来描述不希望被透明的状态栏或者导航栏遮挡的最高位置(status bar, navigation bar, toolbar, tab bar 等)。这个属性的值是一个 length 属性( topLayoutGuide.length)。 这个值可能由当前的 ViewController 或者 NavigationController 或者 TabbarController 决定。
-
一个独立的ViewController,不包含于任何其他的ViewController。如果状态栏可见,topLayoutGuide表示状态栏的底部,否则表示这个ViewController的上边缘。
-
包含于其他ViewController的ViewController不对这个属性起决定作用,而是由容器ViewController决定这个属性的含义:
-
如果导航栏(Navigation Bar)可见,topLayoutGuide表示导航栏的底部。
-
如果状态栏可见,topLayoutGuide表示状态栏的底部。
-
如果都不可见,表示ViewController的上边缘。
-
这部分还比较好理解,总之是屏幕上方任何遮挡内容的栏的最底部。
iOS 11 开始弃用了这两个属性, 并且引入了 Safe Area 这个概念。苹果建议: 不要把 Control 放在 Safe Area 之外的地方
// These objects may be used as layout items in the NSLayoutConstraint API @available(iOS, introduced: 7.0, deprecated: 11.0) open var topLayoutGuide: UILayoutSupport { get } @available(iOS, introduced: 7.0, deprecated: 11.0) open var bottomLayoutGuide: UILayoutSupport { get }
解决办法有两种:
1、在报错的Main.storyboard和LanunchScreen.storyboard如下标记位置去掉安全区域默认的勾选
2、在工程最低版本要求中改为9.0