Created
September 19, 2021 22:28
-
-
Save mohitnandwani/d3473cc7486cf9f1d37ae8dc8721122c to your computer and use it in GitHub Desktop.
A presentation controller which changes the container view size when the trait collection changes
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
class DetailViewPresentationController: UIPresentationController { | |
override var frameOfPresentedViewInContainerView: CGRect { | |
guard let containerView = containerView else { | |
return super.frameOfPresentedViewInContainerView | |
} | |
if traitCollection.verticalSizeClass == .compact { | |
return CGRect(x: 72, y: 64, width: containerView.frame.width - 144, height: containerView.frame.height) | |
} else { | |
return CGRect(x: 0, y: 0, width: containerView.frame.width, height: containerView.frame.height) | |
} | |
} | |
override func containerViewWillLayoutSubviews() { | |
presentedView?.frame = frameOfPresentedViewInContainerView | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment