Skip to content

Instantly share code, notes, and snippets.

@Thomvis
Last active April 25, 2021 15:21
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Thomvis/bf78defea664f3d5921c2881545dd15e to your computer and use it in GitHub Desktop.
Save Thomvis/bf78defea664f3d5921c2881545dd15e to your computer and use it in GitHub Desktop.
// 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