0

我已经检查并尝试了各种答案。但它仍然对我不起作用。这是我的代码,

-(void)animate {

    [img1 startAnimating];

    [UIView animateWithDuration:10
                     animations:^{

                         img1.transform = CGAffineTransformMakeTranslation(0.0, -1000);}];

    [img2 startAnimating];

    [UIView animateWithDuration:13
                     animations:^{
                         img2.transform = CGAffineTransformMakeTranslation(0.0, -1000);}];

}

我想在我按下一个按钮时开始动画,当我按下另一个按钮时停止。它适用于 start 和 stop 。但是当我通过按下再次调用此方法的开始按钮重新启动它时,问题就来了。当我第二次打电话时没有任何反应??????

4

1 回答 1

4

转换无法执行两次

嗨,您需要使用完成块来执行此动画,

像这样在其他地方初始化......

@interface YourClass()

{
    CGAffineTransform trans1 ;

    CGAffineTransform trans2 ;

}

@End
....


    -(void)animate {


        [_img1 startAnimating];

        [UIView animateWithDuration:10
                         animations:^{
                             trans1 = _img1.transform; //  
                             _img1.transform = CGAffineTransformMakeTranslation(0.0, -1000);} completion:^(BOOL finished) {
                                 _img1.transform = trans1;
                             }];

        [_img2 startAnimating];

        [UIView animateWithDuration:13
                         animations:^{
                             trans2 = _img2.transform; 
                             _img2.transform = CGAffineTransformMakeTranslation(0.0, -1000);} completion:^(BOOL finished) {
                                 _img2.transform = trans2;
                             }];

    }
于 2013-10-17T10:59:40.377 回答