Safe Area before iOS 11
andreyrd opened this issue ยท 4 comments
Hey, so prior to iOS 11, the safeArea shortcuts have no effect, they don't offset the view at all.
I'm wondering if it would be worth manually including some offsets, such as for the status bar.
The constraint I was using previously looked like this to account for the status bar:
headerView.top |==| view.top |+| 20
With the new safeArea shortcuts (which are fantastic, by the way, thank you!!!), I can simply do:
headerView.top |==| view.safeArea.top
and it works perfectly across all devices, including iPhone X... if they're all on iOS 11.
On iOS 10, the header now covers the status bar, because the fallback for iOS 10 is no offsets.
I wonder if it'd be worth having MisterFusion actually calculate a fallback safe area offset somehow for iOS 10. It does get kind of complicated because the offsets change and aren't always static.
Of course the obvious workaround for now is to add different constraints based on iOS version:
if #available(iOS 11, *) {
...
headerView.top |==| view.safeArea.top
...
} else {
...
headerView.top |==| view.top |+| 20
...
}
This is something I can look into implementing depending on how much time I will have in the next few days / weeks.
Hi, @andreyrd !
In prior to iOS 11, view.safeArea.top
replaces view.top
in MisterFusion.
In NSLayoutAnchor case,
view.safeAreaLayoutGuide.topAnchor.constraint(equalTo: subview.topAnchor)
equals to
viewController.topLayoutGuide.bottomAnchor.constraint(equalTo: subview.topAnchor)
in prior to iOS11.
A view has the information of top space in iOS11.
But, a viewController has the information of top space in prior to iOS11.
Therefore, a scope of top space is different.
It makes difficult to calculate top space ๐
Ah, I see what you mean about the view and view controller.
And thanks, that will help a lot! :)