iOS:对项目进行两次动画处理 [英] iOS: Animate item twice

查看:228
本文介绍了iOS:对项目进行两次动画处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从核心图形开始。玩一个简单的按钮和标签。我希望此标签在每次单击按钮时旋转180度。它只会在第一次点击时设置动画效果(但是控制台每次点击时都会写 DONE)

Just starting out with core graphics. Playing with a simple button and label. I want this label to rotate 180 degrees on each click of the button. It only animates on the first click (the console does write "DONE" on each click, however)

- (IBAction)btnTest:(id)sender
{

    [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{

        lblTest.layer.transform = CATransform3DMakeRotation(M_PI,0.0,1.0,0.0);

    }completion:^(BOOL finished) {
        if(finished)
            NSLog(@"DONE");
    }];
}


推荐答案

其不起作用的原因是因为在第一次按下按钮时,视图旋转设置为180度。在第二个按钮上,再次将旋转设置为180度,但是由于这与旋转的当前值相同,因此什么也没有发生。您真正想做的是将旋转设置为180度+当前旋转。您可以通过以下更改将当前变换旋转180度来实现此目的。

The reason its not working is because on the first button press, the views rotation is set to 180 deg. On the second button press you set the rotation to 180 deg again but since that is the same as the current value of the rotation, nothing happens. What you really want to be doing is setting the rotation to 180 deg + the current rotation. You can achieve this by rotating the current transform by 180 deg with the following change.

lblTest.layer.transform = CATransform3DRotate(lblTest.layer.transform, M_PI,0.0,1.0,0.0);

这篇关于iOS:对项目进行两次动画处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆