You can handle safeAreaInsets changes of every UIView.
final class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.safeArea.insetsDidChange = { insets in
// If safeAreaInsets of `self.view`, this closure called.
print("view.safeAreaInsets = \(insets)")
}
}
}
extension UIView {
// UIView Extension about Safe Area
var safeArea: SafeAreaExtension { get }
}
class SafeAreaExtension {
// Safe Area Insets handler
var insetsDidChange: ((UIEdgeInsets) -> ())? { get set }
}
- Xcode 9 or greater
- Swift 4 or greater
- iOS 11 or greater
SafeAreaExtension is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SafeAreaExtension'
If you’re using Carthage, simply add
SafeAreaExtension to your Cartfile
:
github "marty-suzuki/SafeAreaExtension"
To run the example project, clone the repo, and run pod install
from the Example directory first.
marty-suzuki, [email protected]
SafeAreaExtension is available under the MIT license. See the LICENSE file for more info.