I have a ViewController with a bunch of UIImageViews that I need to send to the front and animate to the center of the view.
I have tried to call bringSubviewToFront before casting the UIView animation and what seems to be happening is that the view is sent to the top of the stack, but the animation does not happen (even though the completion handler log shows as if the animation DID happen).
The second time i press the button that triggers the animation (considering that this time the view is already at top index, the animation takes place as it should)
Heres my code:
- (void)beginAnimationWithSelectedCountry:(UIView *)countryView
{
if (!countryView) return;
[self.view bringSubviewToFront:countryView];
[UIView animateWithDuration:0.6f delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
countryView.center = CGPointMake(self.view.center.x, self.view.center.y);
} completion:^(BOOL finished) {
NSLog(@"Animation complete");
}];
}
Any thoughts? I've been at this for hours >.<
Thanks
EDIT: If I comment out the bringSubviewToFront the code executes flawlessly with the animation (except the view is under some other views) so i'm preety sure the problem is with the line:
[self.view bringSubviewToFront:countryView];
Heres a screenshot of what I have currently that may shed some more light on the issue: http://d.pr/i/PKoa
Call:
[self.view layoutSubviews];
Right after:
[self.view bringSubviewToFront:countryView];
It will solve your problem.
When you call
[self.view bringSubviewToFront:countryView];
you trigger a new view layout event. You can check this by setting a breakpoint in 'viewDidLayoutSubviews' on your controller.
I had a similar issue: my own code in the 'viewDidLayoutSubviews' method cancelled my animation by resetting the frames of the objects I was trying to animate.
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