Rizon
Rizon

Reputation: 1546

UIView animation ignores duration

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?

Upvotes: 4

Views: 4966

Answers (2)

vijay
vijay

Reputation: 23

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];  
      }];
   }

Upvotes: 1

Wain
Wain

Reputation: 119041

You probably have the animation encapsulated inside another animate and its duration is being used for both of the animations.

Upvotes: 7

Related Questions