I'm using a custom UIPresentationController subclass to manage the presentation of a UIViewController. I'm overriding - (CGRect)frameOfPresentedViewInContainerView
to provide a frame that is inset from the bounds of the containerView.
Now, after some user action on the presentedViewController, I would like to change the frame of the presentedViewController. My question is: Is there a 'natural' way to do this??
How can I adjust the frame of a presentedViewController after it has been presented?
The UIPresentationController class defines specific entry points for manipulating the view hierarchy when presenting a view controller. When a view controller is about to be presented, UIKit calls the presentation controller’s presentationTransitionWillBegin () method.
An object that manages the transition animations and the presentation of view controllers onscreen. From the time a view controller is presented until the time it is dismissed, UIKit uses a presentation controller to manage various aspects of the presentation process for that view controller.
The presented view controller has a transitioning delegate that’s responsible for loading the UIPresentationController and the presentation and dismissal animation controllers. That delegate is an object that conforms to UIViewControllerTransitioningDelegate.
The presentation process managed by a presentation controller is divided into three phases: The presentation phase involves moving the new view controller onscreen through a series of transition animations. The management phase involves responding to environment changes (such as device rotations) while the new view controller is onscreen.
So the way I went about this was to do the following:
I added implemented the following method from <UIContentContainer>
:
- (void)preferredContentSizeDidChangeForChildContentContainer:(id <UIContentContainer>)container
I then simply updated the preferredContentSize on my presentedViewController, got the callback, and animated the frame update within the UIPresentationController.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With