Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dmytro-anokhin/16fc3550a1b2ba28d7b0c7fd2a5a82f9 to your computer and use it in GitHub Desktop.
Save dmytro-anokhin/16fc3550a1b2ba28d7b0c7fd2a5a82f9 to your computer and use it in GitHub Desktop.
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