TopLayoutGuide和BottomLayoutGuide在iOS 11中已弃用

Jam*_*ang 4 autolayout ios11

UIViewControllertopLayoutGuide,并bottomLayoutGuide在iOS的11已被弃用应该用什么替代?

Jam*_*ang 13

以前在你的UIViewController:

customView.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor).isActive = true
customView.bottomAnchor.constraint(equalTo: bottomLayoutGuide.topAnchor).isActive = true
Run Code Online (Sandbox Code Playgroud)

现在你应该使用:

customView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
customView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true
Run Code Online (Sandbox Code Playgroud)

请注意从更改bottomAnchortopAnchor.这是因为顶部布局指南是视图控制器顶部的矩形,因此为了将内容限制在顶部,您需要指南的底部锚点.新的保险箱布局指南是视图的矩形部分,不受条形和其他内容的影响,因此您需要顶部锚点.反之亦然,底部布局指南.

  • 我似乎无法使用可视化布局格式语言.你能举个例子吗?我得到' - [NSLayoutYAxisAnchor nsli_superitem]:无法识别的选择器' (4认同)