使用Quartz 2D进行仿射变换的序列

时间:2011-12-24 17:06:36

标签: ios quartz-graphics

我正在尝试使用iOS中的UIAlertView在OS X中模拟错误的密码输入动画。基本上我希望它翻译警报左,然后翻译正确。这就是我在做的事情:

    [UIView animateWithDuration:0.5 
                 animations:^{
                     alertView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 200, 0);
                     alertView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, -200, 0);
                 }];

然而,这没有达到预期的效果。瞬间向右发出警报,然后顺利转向左侧。如何让两个翻译在彼此之后顺利进行?

1 个答案:

答案 0 :(得分:8)

试试这个:

[UIView animateWithDuration:0.5 animations:^{

        alertView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 200, 0);

    } completion:^(BOOL finished) {

        [UIView animateWithDuration:0.5 animations:^{
            alertView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, -200, 0);
        }];
    }];

但我会像这样做动画:

[UIView animateWithDuration:0.1 animations:^{

        alertView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 20, 0);

    } completion:^(BOOL finished) {

        [UIView animateWithDuration:0.1 animations:^{

            alertView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, -20, 0);

        } completion:^(BOOL finished) {

            [UIView animateWithDuration:0.1 animations:^{
                alertView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 0, 0);
            }];

        }];
    }];

由你决定! ; - )