2011-12-24 66 views
4

我試圖用iOS中的UIAlertView在OS X中模擬不正確的密碼輸入動畫。本質上,我希望它能夠翻譯左側的警報然後右側翻譯。這是我在做什麼:使用Quartz 2D仿射變換的順序

[UIView animateWithDuration:0.5 
       animations:^{ 
        alertView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 200, 0); 
        alertView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, -200, 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); 
      }]; 

     }]; 
    }]; 

你了! ;-)

+0

完美!我嘗試過使用完成塊,但似乎沒有工作。然而,你的解決方案。謝謝。 – lukestringer90 2011-12-24 17:43:33

+0

歡迎您! :) – Ecarrion 2011-12-24 17:44:27