Question
I am trying to present view controller modally (a UIImagePickerController to be precise) while animating some views before the presentation.
It's important to note that the animations and the presentation of the view are not chained, and there can be a time-gap between the views animating and modally presenting the image picker.
With all that said, while I present the view controller, it seems that all of the subviews of the current view I'm in (the view I'm presenting from - the parent view controller's view) are being reset to their original "storyboard" positions, which causes all of the animations I've done in the view BEFORE presenting the image picker to reset.
Another thing worth noting, is that I use AutoLayout to position the views I animate.
I've added a sample animation showing the problem - notice how the "Animate" button snaps back to it's original position right after I click the "Present Modal View Controller" button (I've toggled "Slow Animations" right before presenting the modal view controller so you can see the "Animate" button snaps back).
I'm also adding a link to the example app shown in the animation so you examine the problem more deeply, click here to download it.
Answer
To solve the issue, I used @kokx's answer, and animated the Auto Layout constraints of the views instead of their frame values. To do that, I simply created outlets for the constraints I wanted to modify, and modified the constant
property of the constraints.
To animate the change, simply call the original [UIView animateWithDuration:options:animations:completion:]
while replacing any animation code it's animations:
part with a call to [self.view layoutIfNeeded]
.