@@ -46,8 +46,6 @@ class ModalDialogViewController: UIViewController {
4646 super. init ( nibName: nibNameOrNil, bundle: nibBundleOrNil)
4747
4848 transitionController. transition = ModalDialogTransition ( )
49- preferredContentSize = . init( width: 200 , height: 200 )
50- modalPresentationStyle = . overCurrentContext
5149 }
5250
5351 required init ? ( coder aDecoder: NSCoder ) {
@@ -67,7 +65,19 @@ class ModalDialogViewController: UIViewController {
6765 }
6866}
6967
70- class ModalDialogTransition : SelfDismissingTransition {
68+ class ModalDialogTransition : SelfDismissingTransition , TransitionWithPresentation {
69+
70+ public func defaultModalPresentationStyle( ) -> UIModalPresentationStyle ? {
71+ return . custom
72+ }
73+
74+ public func presentationController( forPresented presented: UIViewController ,
75+ presenting: UIViewController ? ,
76+ source: UIViewController ) -> UIPresentationController ? {
77+ return ModalDialogPresentationController ( presentedViewController: presented,
78+ presenting: presenting)
79+ }
80+
7181
7282 func willBeginTransition( withContext ctx: TransitionContext , runtime: MotionRuntime ) -> [ Stateful ] {
7383 let size = ctx. fore. view. frame. size
@@ -113,3 +123,18 @@ class ModalDialogTransition: SelfDismissingTransition {
113123 dismisser. dismissWhenGestureRecognizerBegins ( pan)
114124 }
115125}
126+
127+ private final class ModalDialogPresentationController : UIPresentationController {
128+
129+ override var frameOfPresentedViewInContainerView : CGRect {
130+ guard let containerView = containerView else {
131+ assertionFailure ( " Missing container view during frame query. " )
132+ return . zero( )
133+ }
134+ let size = CGSize ( width: 200 , height: 200 )
135+ return CGRect ( x: containerView. bounds. midX - size. width / 2 ,
136+ y: containerView. bounds. midY - size. height / 2 ,
137+ width: size. width,
138+ height: size. height)
139+ }
140+ }
0 commit comments