Skip to content

Instantly share code, notes, and snippets.

@mohitnandwani
Created September 19, 2021 22:28
Show Gist options
  • Save mohitnandwani/d3473cc7486cf9f1d37ae8dc8721122c to your computer and use it in GitHub Desktop.
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
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