Mar 31, 2016:  ~ 1 min read

Better interaction between viewWillTransitionToSize and CGSize

Instead of checking if size.width > size.height, we can have three handy CGSize extensions:

extension CGSize {
  var isCompact: Bool { return height > width + delta }
  var isWide: Bool { return width > height + delta }
  var isSquare: Bool { return abs(width - height) < delta } 

For usage within viewWillTransition(to:with:) I don't think the delta will be really needed, but if we want to use these properties for our own custom views, it might come in handy. Modify its value to fit your own needs, of course.

Subscribe to my monthly newsletter.
No spam, unsubscribe at any time.