如何连续几次动画UIImageView旋转

时间:2011-01-05 13:22:41

标签: iphone cocoa-touch uiimageview core-animation rotation

我正在尝试为UIImage视图设置动画,每次顺时针旋转90度。 出于某种原因,第一个旋转动画可以工作,但随后它会停止(即使另一个视图调整大小动画继续工作)。这是为什么? (我到处看,但找不到答案)

{
        [btn setFrame:CGRectMake(previousX, previousY, BUTTON_WIDTH, BUTTON_HEIGHT)];
        [self.view insertSubview:btn atIndex:0];

        [UIView beginAnimations:@"ButtonAnimation" context:nil];

        [UIView setAnimationDuration:2.5];

        [UIView setAnimationCurve:UIViewAnimationCurveLinear];

        CGRect rect = CGRectMake(previousX,previousY+BUTTON_HEIGHT,BUTTON_WIDTH,BUTTON_HEIGHT);

         btn.frame = rect;

        [UIView setAnimationBeginsFromCurrentState:YES]; 

        ++ButtonCounter;
         if (ButtonCounter < [btnArray count])
            {

                [UIView setAnimationDidStopSelector:@selector(didStopReal)];
            }
            else
            {
                ButtonCounter = 0; 
            }


        // The transform matrix
        CGAffineTransform transform = 
        CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(90));

        imgArrowView.transform = transform;


        [UIView setAnimationDelegate:self];
        [UIView commitAnimations];
}

-(void) didStopReal
{
    [self animteReal:ButtonCounter];
}

1 个答案:

答案 0 :(得分:3)

相对于当前变换构建变换矩阵:

CGAffineTransform transform = 
CGAffineTransformRotate(imgArrowView.transform, DEGREES_TO_RADIANS(90));