I'm using a custom presentation controller to make something similar to UIAlertView
. I want it to move up when the keyboard shows. In the UIKeyboardWillShowNotification
handler, I'm grabbing the new keyboard frame, storing it in a property, and then calling:
self.presentedView.frame = [wself frameOfPresentedViewInContainerView];
In my implementation of -frameOfPresentedViewInContainerView
, I take the current keyboard height into account.
This works perfectly, but it feels a little dirty to be modifying the frame of self.presentedView
directly. I tried triggering layout on the container view with various permutations of setNeedsLayout
and layoutIfNeeded
, but nothing causes the presented view to move other than just setting its frame directly.
Is there a better way to do this than to just change the frame myself?
You need to update the preferredContentSize
of your presented VC.
The presentation controller does not know how and when the layout of the presented VC will change after the presentation finishes. It only knows it's size and the position needed to perform the transition.
But the presentation controller has a nice delegate method inherited from UIContentContainer
: preferredContentSizeDidChange(forChildContentContainer container: UIContentContainer)
So what you should do is:
preferredContentSize
right aftercontainerView
property of your presentation controller 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