Here is the constraints:
It works fine on iOS11, but doesn't work on iOS9 and iOS 10.
You can download the example over here.
Here is the constraints:
It works fine on iOS11, but doesn't work on iOS9 and iOS 10.
You can download the example over here.
https://developer.apple.com/documentation/uikit/uiview/2891102-safearealayoutguide
safeAreaLayoutGuide is introduced in iOS 11. No wonder it doesn't work in iOS 9 and 10.
For older versions, consider using layoutMargins property instead.
let window = UIApplication.shared.keyWindow
let topPadding = window?.layoutMargins
are you trying to achieve this? (ios10 on the left and ios 11 on the right)
If yes, you can do next:
I checked your code and found top constraint of your Red View is not correct. Your Red View should align top from Safe Area instead of superview.
In my case, setting edgesForExtendedLayout to an empty array for iOS 10 had the desired effect. Full answer here: https://stackoverflow.com/a/51247890/3885491
If you're using storyboards then it would work because Storyboard is backward-compatible. Bare in mind that storyboards hides the difference in the actual code and not good for deep understanding...
If you're doing it programmatically then:
See Safe Area Layout Guide Tutorial
. SafeArea is available in iOS 11 only. For non-iOS 11 you must use topLayoutGuide.bottomAnchor
.