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.