I'm trying to perform an animation from within a UIView subclass, on one of its subviews.
The animation duration ignores any value I try to set it to, and just performs on a permanent duration of ~2 secs.
The finished
flag returns with True.
[UIView animateWithDuration:0.5f animations:^{
img.frame = newFrame;
} completion:^(BOOL finished) {
NSLog(@"result: %d", finished);
}];
When I'm using the old way, it works fine:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5f];
img.frame = newIconRectFinal;
[UIView commitAnimations];
What could be the problem?
You probably have the animation encapsulated inside another animate and its duration is being used for both of the animations.
Use this line of code before start the animation write this single line code.
[UIView setAnimationsEnabled:YES];
see below the code it will work. Now it will not ignore duration
-(void)doAnimation
{
view2=(UIView*)[self.view viewWithTag:100];
UIView setAnimationsEnabled:YES];
[UIView animateWithDuration:3.0 animations:^{
view2.frame=CGRectMake(0, 30, 1024,768);
view2.alpha=1.0
completion:^(BOOL finished){
view2.frame=CGRectMake(0, 0, 1024,768);
view2.alpha=0.0
[weakSelf doAnimation];
}];
}
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