Reputation: 93
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.
Upvotes: 2
Views: 4673
Reputation: 3699
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
Upvotes: 2
Reputation: 1190
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
Upvotes: 0
Reputation: 36287
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
.
Upvotes: -1
Reputation: 8147
are you trying to achieve this? (ios10 on the left and ios 11 on the right)
If yes, you can do next:
Upvotes: 1
Reputation: 10625
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.
Upvotes: 0