iOS 11.0中不推荐使用“ bottomLayoutGuide”:使用view.safeAreaLayoutGuide.bottomAnchor而不是bottomLayoutGuide.topAnchor吗?

时间:2019-05-26 08:57:11

标签: swift

底部布局指南显示在ios 11中已弃用?在开发应用程序时。尽管我尝试使用布局锚但不起作用,但我已附上我的代码问题的图片

 override open func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        coordinator.animate(alongsideTransition: { (transitionCoordinatorContext) -> Void in
            let orient = UIApplication.shared.statusBarOrientation

            for (index, var layoutAnchor) in self.arrBottomAnchor.enumerated() {

                layoutAnchor.isActive = false

                switch orient {
                case .portrait:
                   layoutAnchor = self.arrViews[index].bottomAnchor.constraint(equalTo: self.bottomLayoutGuide.topAnchor)


                case .landscapeLeft,.landscapeRight :
                    layoutAnchor = self.arrViews[index].bottomAnchor.constraint(equalTo: self.bottomLayoutGuide.bottomAnchor)

1 个答案:

答案 0 :(得分:0)

使用view.safeAreaLayoutGuide.bottomAnchor代替bottomLayoutGuide.topAnchor

if #available(iOS 11.0, *) {
    layoutAnchor = self.arrViews[index].bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor)
} else {
    layoutAnchor = self.arrViews[index].bottomAnchor.constraint(equalTo: self.bottomLayoutGuide.topAnchor)
}