Skip to content

Instantly share code, notes, and snippets.

@jamesrochabrun
Last active May 5, 2020 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesrochabrun/1f02c6377ecd895e952075e70df21d04 to your computer and use it in GitHub Desktop.
Save jamesrochabrun/1f02c6377ecd895e952075e70df21d04 to your computer and use it in GitHub Desktop.
/// 1
lazy var displayModeCustomButton: Button = {
let button = Button(type: .system, image: SplitViewControllerViewModel.displayModeButtonImageFor(self.displayMode), target: self, selector: #selector(togglePrefferDisplayModeExecutingCompletion))
button.constrainWidth(constant: 44.0)
button.constrainHeight(constant: 44.0)
button.imageEdgeInsets = .init(top: 8.0, left: 8.0, bottom: 8.0, right: 8.0)
return button
}()
/// 2
@objc func togglePrefferDisplayModeExecutingCompletion(_ executing: Bool = true) {
UIView.animate(withDuration: 0.3, animations: {
/// 3
self.preferredDisplayMode = self.displayMode == .allVisible ? .primaryHidden : .allVisible
self.displayModeCustomButton.setImage(SplitViewControllerViewModel.displayModeButtonImageFor(self.preferredDisplayMode), for: .normal)
}) { _ in
/// perform some action if needed after animation completion.
}
}
extension SplitViewController: UISplitViewControllerDelegate {
/// 4
func splitViewController(_ svc: UISplitViewController, willChangeTo displayMode: UISplitViewController.DisplayMode) {
/// delegate method that is triggered as soon `prefferDisplayMode` is set.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment