Last active
March 5, 2019 03:28
-
-
Save rafattouqir/6f21573ddd95e09b643e44f1e00e263d to your computer and use it in GitHub Desktop.
iOS 11 safe area layout guide backwards compatibility upto iOS 9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let safeAreaTopAnchor:NSLayoutYAxisAnchor? | |
if #available(iOS 11.0, *) { | |
safeAreaTopAnchor = contentView.safeAreaLayoutGuide.topAnchor | |
} else { | |
// Fallback on earlier versions | |
var parentViewController: UIViewController? { | |
var parentResponder: UIResponder? = self | |
while parentResponder != nil { | |
parentResponder = parentResponder!.next | |
if let viewController = parentResponder as? UIViewController { | |
return viewController | |
} | |
} | |
return nil | |
} | |
safeAreaTopAnchor = parentViewController?.topLayoutGuide.bottomAnchor | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment