swift - SnapKit 3.2: 适应iOS 11(iPhone X)返回safeAreaLayoutGuide.snp

无言

2017-12-29T11:15:46Z||2017-12-29T11:15:46Z

代码来自这里

import SnapKit

extension UIView {
    public var safeArea: ConstraintBasicAttributesDSL {
        if #available(iOS 11.0, *) {
            return safeAreaLayoutGuide.snp
        }
        return self.snp
    }
}

然后可以在代码里使用view.safeArea,在iOS 11下会返回safeAreaLayoutGuide.snp,在iOS 11前会继续返回UIView.snp