iOS 11 safe area layout guide backwards compatibility

前端 未结 16 1161
忘了有多久
忘了有多久 2020-12-02 05:42

Is enabling Safe Area Layout Guides compatible to iOS below 11?

16条回答
  •  被撕碎了的回忆
    2020-12-02 06:06

    Simple Swift 4 Solution:

    First set to top constraint priority to the safe area to 750, then:

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        
        if #available(iOS 11, *) {
            // Safe area constraints already set.
        } else {
            NSLayoutConstraint.activate([
                self.yourView.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor)
            ])
        }
    }
    

提交回复
热议问题