2015-12-22 96 views
-1

我想用3個步驟創建動畫。第一步應該放大照片上的正確方向。第二步是在3秒內放大其他圖片的效果。最後一步是再次在3秒內用不同的圖像縮小。我完全按照我的要求完成了前兩步,但是當我添加3步時,一些事情出錯了。它就像它試圖做2和3步一起。請幫幫我。這是我的代碼。我的UIView動畫有什麼問題?

imgAnimationBase.image = [UIImage imageNamed:@"animation-1.jpg"]; 

imgAnimationBase.alpha = 1.0; 
imgAnimationBase.transform =CGAffineTransformMakeScale(1.5,1.5); 
imgAnimationBase.frame=CGRectMake(20, imgAnimationBase.frame.origin.y, imgAnimationBase.frame.size.width, imgAnimationBase.frame.size.height); 

[UIView transitionWithView:imgAnimationBase 
    duration:3.0f 
    options:UIViewAnimationOptionTransitionCrossDissolve 
animations:^{ 
    imgAnimationBase.frame=CGRectMake(-110, imgAnimationBase.frame.origin.y, imgAnimationBase.frame.size.width, imgAnimationBase.frame.size.height); 
} 
      completion:^(BOOL finished) { 

       imgAnimationBase.transform =CGAffineTransformMakeScale(1,1); 
       imgAnimationBase.frame=CGRectMake(10, imgAnimationBase.frame.origin.y, imgAnimationBase.frame.size.width, imgAnimationBase.frame.size.height); 
       [UIView transitionWithView:imgAnimationBase 
           duration:3.0f 
            options:NO 
           animations:^{ 
            imgAnimationBase.image = [UIImage imageNamed:@"animation-2.jpg"]; 
            [UIView animateWithDuration:3.0 animations:^{ 
              imgAnimationBase.alpha = 1.0; 
              imgAnimationBase.transform =CGAffineTransformMakeScale(2,2); 

            }]; 

           } 
             completion:^(BOOL finished) { 



              [UIView transitionWithView:imgAnimationBase 
                   duration:3.0f 
                   options:NO 
                  animations:^{ 
                   imgAnimationBase.image = [UIImage imageNamed:@"animation-3.jpg"]; 
                   [UIView animateWithDuration:3.0 animations:^{ 

                    imgAnimationBase.alpha = 1.0; 
                    imgAnimationBase.transform =CGAffineTransformMakeScale(1,1); 
                   }]; 

                  } 
                  completion:^(BOOL finished) { 

                  }]; 
             }]; 
       }]; 
+0

你爲什麼要在動畫塊中調用'[UIView animateWithDuration:animations:]'? – Losiowaty

+0

啊,是的,謝謝@Losiowaty,我錯誤地插入它。它解決了這個問題。不敢相信這樣的錯誤。寫下來作爲答案,我會標記它。 –

回答

1

正如在評論中提到 - 沒有必要調用[UIView animateWithDuration: animations:]秒的時候,你已經在animations塊。