TopLayoutGuide 和 BottomLayoutGuide 在 iOS 11 中已弃用 [英] TopLayoutGuide and BottomLayoutGuide Deprecated in iOS 11

查看:24
本文介绍了TopLayoutGuide 和 BottomLayoutGuide 在 iOS 11 中已弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIViewControllertopLayoutGuidebottomLayoutGuide 在 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

注意从 bottomAnchortopAnchor 的变化.这是因为顶部布局指南是视图控制器顶部的一个矩形,所以为了将您的内容限制在顶部,您需要指南的底部锚点.新的安全区布局指南是视图的矩形部分,没有被条和其他内容遮挡,因此您需要顶部锚点.底部布局指南反之亦然.

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.

这篇关于TopLayoutGuide 和 BottomLayoutGuide 在 iOS 11 中已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆