Rightpoint / Anchorage

A collection of operators and utilities that simplify iOS layout code.
MIT License
630 stars 46 forks source link

Deal with deprecation of UIViewController top/bottom layout guide in iOS 11 #45

Open ZevEisenberg opened 7 years ago

ZevEisenberg commented 7 years ago

Not sure what the right approach is. Do we have to use the new edge inset guide on the view?

ZevEisenberg commented 7 years ago

Reference: https://useyourloaf.com/blog/safe-area-layout-guide/

ZevEisenberg commented 7 years ago

Clearly, the new approach is to use the safeAreaLayoutGuide on iOS 11+. We should also have something along these lines for all the hybrid anchors:

var safeCenterAnchors: AnchorPair<NSLayoutXAxisAnchor, NSLayoutYAxisAnchor> {
    if #available(iOS 11.0, *) {
        return AnchorPair(first: safeAreaLayoutGuide.centerXAnchor, second: safeAreaLayoutGuide.centerYAnchor)
    }
    else {
        return centerAnchors
    }
}

In order to do this in my app, I also had to add this to expose the internal initializer:

extension AnchorPair {
    init(first: T, second: U) {
        self.first = first
        self.second = second
    }
}
ZevEisenberg commented 6 years ago

Semi-duplicated by #59