UIViewController
的topLayoutGuide
和bottomLayoutGuide
在iOS 11中已被弃用。应该使用什么替代品?
UIViewController
的topLayoutGuide
和bottomLayoutGuide
在iOS 11中已被弃用。应该使用什么替代品?
之前在你的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
。这是因为顶部布局指南是视图控制器顶部的矩形,因此为了将您的内容限制在顶部,您希望使用指南的底部锚点。新的安全布局指南是未被栏和其他内容遮挡的视图的矩形部分,因此您需要顶部锚点。底部布局指南亦然。
view.safeAreaLayoutGuide.topAnchor
中的view
是什么意思?它是指customView
吗? - chudin26