I’m trying to work on a UIButton animation where the button moves to a point and then is set hidden to be true. However when I tried working on the following code, the button disappeared even before the animation was completed. Am I doing it correctly? Any suggestions?
[UIView animateWithDuration:0.8
animations:^{
selectedCurveIndex = 0;
[tradebutton moveTo:
CGPointMake(51,150) duration:0.8
option:curveValues[UIViewAnimationOptionCurveEaseInOut]];
}
completion:^(BOOL finished){
[tradeButton setHidden:TRUE];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"ButtonView"];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:vc animated:NO];
}];
The problem is that you create a second, inner animation block in the
moveTo:duration:option:method, and you set all of the animatable properties in that inner block. You don’t set any animatable properties in the outer block.That means that the system immediately thinks that the outer animation has finished, and calls the completion block right away. Meanwhile, the inner animation block is still going.
Stop using
moveTo:duration:option:. It saves you almost nothing, and ends up giving you trouble like this. Throw it out and try something like this instead:Note that
UIViewAnimationOptionCurveEaseInEaseOutis the default for most animations.