如何连续几次对 UIImageView 旋转进行动画处理

发布于 2024-10-10 04:07:51 字数 1213 浏览 0 评论 0原文

我正在尝试为 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];
}

I'm trying to animate an UIImage view, each time by 90 degree clockwise.
For some reason, the first rotation animation works, but then it stops (even though the other view resizing animation continue to work). Why is that? (I looked everywhere but couldn't find an answer)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放低过去 2024-10-17 04:07:51

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

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

Build your transform matrix relative to the current transform:

CGAffineTransform transform = 
CGAffineTransformRotate(imgArrowView.transform, DEGREES_TO_RADIANS(90));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文