Created
October 8, 2017 10:56
-
-
Save dmytro-anokhin/16fc3550a1b2ba28d7b0c7fd2a5a82f9 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
override func viewWillLayoutSubviews() { | |
super.viewWillLayoutSubviews() | |
// Update display state | |
displayMode = suggestDisplayMode(for: traitCollection) | |
let size = view.bounds.size | |
switch displayMode { | |
case .sideBySide: | |
// Add subviews. Order is not important | |
view.addSubview(leftContainerView) | |
view.addSubview(rightContainerView) | |
// Update left column width | |
leftColumnWidth = suggestLeftColumnWidth(for: size) | |
// Position container views | |
leftContainerView.frame = leftColumnFrame(for: size) | |
rightContainerView.frame = rightColumnFrame(for: size) | |
case .one: | |
// Add/remove subviews based on display focus | |
switch displayFocus { | |
case .left: | |
view.addSubview(leftContainerView) | |
leftContainerView.frame = fullFrame(for: size) | |
rightContainerView.removeFromSuperview() | |
case .right: | |
view.addSubview(rightContainerView) | |
rightContainerView.frame = fullFrame(for: size) | |
leftContainerView.removeFromSuperview() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment