iOS 11中弃用的TopLayoutGuide和BottomLayoutGuide [英] TopLayoutGuide and BottomLayoutGuide Deprecated in iOS 11
问题描述
UIViewController
的topLayoutGuide
和bottomLayoutGuide
在iOS 11中已弃用.应该替换什么?
UIViewController
's topLayoutGuide
and bottomLayoutGuide
are deprecated in iOS 11. What should be the replacement?
推荐答案
以前在您的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
的更改.这是因为顶部布局向导是视图控制器顶部的矩形,因此为了将内容限制在顶部,您需要向导的底部锚点.新的保险柜布局指南是视图的矩形部分,没有任何条形图和其他内容遮挡,因此您需要顶部锚点.反之亦然,适用于底部布局指南.
Note the change from bottomAnchor
to topAnchor
. This is because the top layout guide was a rectangle at the top of the view controller, so in order to constraint your content to the top, you wanted the bottom anchor of the guide. The new safe are layout guide is a rectangle portion of the view unobscured by bars and other content, so you want the top anchor. And vice-versa for the bottom layout guide.
这篇关于iOS 11中弃用的TopLayoutGuide和BottomLayoutGuide的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!