Is enabling Safe Area Layout Guides compatible to iOS below 11?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Oracle equivalent of PostgreSQL INSERT…RETURNING *
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
I found a more convenient way where you only need to subclass the
NSLayoutConstraint
that is pinned to yoursafeArea
.It's kinda hacky since you have to get the ViewController from a UIView but in my opinion, that's an easy and good alternative until Apple finally fixes backward compatibility for the safeArea in Xibs.
Subclass:
Xib:
There's definitely at least one backwards compatibility issue with iOS 11's safe area constraints that I've observed in the Xcode 9 GM--pushed view controllers with safe area constraints.
If your navigation bar is hidden and you push a safe area top-constrained view, the pushed view will overlap the status bar on iOS 9 & 10.
If the navigation bar is visible, and "under top bars" disabled, the pushed view will still slide up under the nav bar to get to the top of the screen. The navigation bar is placed correctly.
On iOS 11, the layout will be correct in both cases.
Here's a simple example: http://www.filedropper.com/foobar
And here's a video of it w/nav bar hidden (iOS 10.3 on left, iOS 11 on right): https://vimeo.com/234174841/1e27a96a87
Here's a version where the nav bar is visible (enabled in the nib): https://vimeo.com/234316256/f022132d57
I filed this as Radar #34477706.
Thanks to @Sander for pointing out the nav bar visible case.
Yes, your project/app will work in iOS versions prior to iOS 11 without any issue. In iOS versions prior to 11, it replaces/considers Safe Area Layout into normal AutoLayout and follows Rules of Top and Bottom layout guide.
I tested my existing project with and without 'SafeAreaLayout' on both platforms (iOS 11 and backward iOS 10). It's working fine.
Here is sample snapshot with result, By enabling or disabling Safe Area layout, won't effect on existing design.
Safe Area Layout:
AutoLayout
When you have a generic ViewController that all your ViewControllers extend, another solution would be to put the items that should be adjusted in an IBOutletCollection and adjust them programmatically in that GenericViewController. Here's my code :
Here's what I did with my Projects
In my case both my
topConstraint
andbottomConstraint
s are@IBOutlet
s. This is also compatible foriOS 8
.My initial configuration for the top and bottom constraints are for the normal iPhones, which is why I'm only editing the constraints for iPhone X
.
NOTE:
self.view
is your superView which is why I'm using it forsafeAreaInsets
I was using this in Objective-C with good result for iOS 10. In case you use SafeArea in your xib then you may add in your
viewDidLoad
: