Last active
April 25, 2021 15:21
-
-
Save Thomvis/bf78defea664f3d5921c2881545dd15e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This view overrides safeAreaInsets in order to work around | |
// (possibly erroneous) behavior of UIKit where safe area insets change | |
// when a view is transformed. (see http://www.openradar.me/35532074) | |
// | |
// Use this view as the direct subview of the view that has the transform applied. | |
// This view's frame should be equal to the superview's bounds for this to work. | |
@objc public class TransformIgnoringSafeAreaInsetsView: UIView { | |
@available(iOS 11.0, *) | |
override public var safeAreaInsets: UIEdgeInsets { | |
guard let superview = self.superview, superview.transform != .identity else { | |
return super.safeAreaInsets | |
} | |
// we make a lot of assumptions and test one of them here | |
assert(self.frame == superview.bounds) | |
return superview.safeAreaInsets | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment