UIView commitAnimations - does not animate on second run

Discussion in 'iOS Programming' started by TenaciousG, Oct 19, 2009.

  1. macrumors newbie

    Joined:
    Oct 14, 2009
    #1
    Hi!
    I´m running this code to scale and move an image in animation. It works perfectly the first run, but the next time I run this code the image does not animate.
    I´ve put NSLog statements before and after the transforms to see if the image is affected. See the results below the code

    Code:
    -(void)animateShowImage:(UIButton *)button
    {
         //set the starting animate position
         CGRect frameRect = imageView.frame;
         
         frameRect.size.width = button.frame.size.width;
         frameRect.size.height = button.frame.size.height;
         frameRect.origin = button.frame.origin;
         imageView.frame = frameRect;
         
         
         NSLog(@"imageview width : %f", imageView.frame.size.width);
         NSLog(@"imageview height : %f", imageView.frame.size.height);
         NSLog(@"imageview x : %f", imageView.frame.origin.x);
         NSLog(@"imageview y : %f", imageView.frame.origin.y);
         
         [UIView beginAnimations:nil context:NULL];
         [UIView setAnimationDuration:1.2];
         
         CGAffineTransform move = CGAffineTransformMakeTranslation(30, 20);
         CGAffineTransform scale = CGAffineTransformMakeScale(3,3);
         
         CGAffineTransform finalTransform = CGAffineTransformConcat(move, scale);
         imageView.transform = finalTransform;
         
         [UIView commitAnimations]; 
         
         NSLog(@"imageview width : %f", imageView.frame.size.width);
         NSLog(@"imageview height : %f", imageView.frame.size.height);
         NSLog(@"imageview x : %f", imageView.frame.origin.x);
         NSLog(@"imageview y : %f", imageView.frame.origin.y);
    }
    NSLog first run:
    Code:
    2009-10-19 19:13:41.339 MyProject[15847:207] imageview width : 48.000000
    2009-10-19 19:13:41.341 MyProject[15847:207] imageview height : 45.000000
    2009-10-19 19:13:41.341 MyProject[15847:207] imageview x : 8.000000
    2009-10-19 19:13:41.342 MyProject[15847:207] imageview y : 57.000000
    (gdb) continue
    Current language:  auto; currently objective-c
    2009-10-19 19:13:44.649 MyProject[15847:207] imageview width : 144.000000
    2009-10-19 19:13:44.650 MyProject[15847:207] imageview height : 135.000000
    2009-10-19 19:13:44.650 MyProject[15847:207] imageview x : 50.000000
    2009-10-19 19:13:45.080 MyProject[15847:207] imageview y : 72.000000
    NSLog second run:
    Code:
    2009-10-19 19:13:51.487 MyProject[15847:207] imageview width : 48.000000
    2009-10-19 19:13:51.488 MyProject[15847:207] imageview height : 45.000000
    2009-10-19 19:13:51.489 MyProject[15847:207] imageview x : 8.000000
    2009-10-19 19:13:51.489 MyProject[15847:207] imageview y : 57.000000
    (gdb) continue
    2009-10-19 19:13:54.424 MyProject[15847:207] imageview width : 48.000000
    2009-10-19 19:13:54.425 MyProject[15847:207] imageview height : 45.000000
    2009-10-19 19:13:54.425 MyProject[15847:207] imageview x : 8.000000
    2009-10-19 19:13:57.433 MyProject[15847:207] imageview y : 57.000000
    I can´t figure out what I´m doing wrong. Any help is apprechiated!
     

Share This Page