作者:关注前世男友 | 来源:互联网 | 2023-01-26 13:58
UIViewController
的topLayoutGuide
,并bottomLayoutGuide
在iOS的11已被弃用应该用什么替代?
1> James Kuang..:
以前在你的UIViewController
:
customView.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor).isActive = true
customView.bottomAnchor.constraint(equalTo: bottomLayoutGuide.topAnchor).isActive = true
现在你应该使用:
customView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
customView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true
请注意从更改bottomAnchor
到topAnchor
.这是因为顶部布局指南是视图控制器顶部的矩形,因此为了将内容限制在顶部,您需要指南的底部锚点.新的保险箱布局指南是视图的矩形部分,不受条形和其他内容的影响,因此您需要顶部锚点.反之亦然,底部布局指南.
我似乎无法使用可视化布局格式语言.你能举个例子吗?我得到' - [NSLayoutYAxisAnchor nsli_superitem]:无法识别的选择器'