Fixed
It turns out the animation was being called twice. I've now fixed it so the animation is only called once and it works perfectly.
I suspect it might be something related to my use of child view controllers, but I'm noticing some strange behaviour when I try to remove the child view controller's view with an animation.
I'm adding the child view controller to the parent, along with the child view controller's view, and animating that view from the bottom of the screen. This works perfectly — my issue is when I try to remove the child view/view controller. I'm animating the child's view to the bottom of the screen, and then calling [self.view removeFromSuperview]
in the completion block, but the view is removed immediately (so no animation takes place). If I delete the [self.view removeFromSuperview]
line, the animation works correctly, but then the view isn't removed from the parent view controller's view.
Adding the child view controller
(this works as intended)
ChildViewController *myChildViewController = [[ChildViewController alloc] init];
myChildViewController.view.frame = CGRectMake(0.f, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - 64.f);
[self addChildViewController:myChildViewController];
[self.view addSubview:myChildViewController.view];
[myChildViewController didMoveToParentViewController:self];
[UIView animateWithDuration:0.75f delay:0.f usingSpringWithDamping:0.6f initialSpringVelocity:0.75f options:0 animations:^{
myChildViewController.view.frame = CGRectMake(0.f, 64.f, self.view.frame.size.width, self.view.frame.size.height - 64.f);
} completion:nil];
Removing the child view controller
(this doesn't work — the view is removed immediately, instead of after completion)
[UIView animateWithDuration:0.75f delay:0.f usingSpringWithDamping:0.6f initialSpringVelocity:0.75f options:0 animations:^{
self.view.frame = CGRectMake(0.f, self.view.superview.frame.size.height, self.view.frame.size.width, self.view.frame.size.height);
} completion:^(BOOL finished) {
if (finished)
{
[self willMoveToParentViewController:self.parentViewController];
[self.view removeFromSuperview];
[self removeFromParentViewController];
}
}];
I've even tried removing [self willMoveToParentViewController:self.parentViewController]
and [self removeFromParentViewController]
just to see if that changed anything, but as long as [self.view removeFromSuperview]
is there, the view disappears immediately.