2015-04-01 43 views
0

當我爲視圖的變換設置動畫時,在第一個動畫完成之前重置另一個動畫中的變化,一切都很好(以旋轉顯示)。動畫順利切換到新的目標:UIView縮放動畫超時發生變化

但我這樣做有規模的時候,動畫輝煌過沖:

這裏是斷碼:

UIView.animateWithDuration(1) { 
    self.someView.layer.transform = CATransform3DMakeScale(0.001, 0.001, 1) 
} 
UIView.animateWithDuration(1, 
    delay: 0.5, 
    options: nil, 
    animations: { 
     self.someView.layer.transform = CATransform3DIdentity 
    }, completion: nil 
) 

有沒有其他人看過?難道我做錯了什麼?

編輯:有沒有一個很好的解決方法?編輯2:我相信這是this question的副本,並且我正在投票結束。

+0

可能重複[製作具有UIViewAnimationOptionBeginFromCurrentState工作不正常transform.scale(http://stackoverflow.com/questions/26543763/ animate-transform-scale-with-uiviewanimationoptionbeginfromcurrentstate-not-work) – s4y 2015-04-01 21:43:53

回答

1

This blog post提供了答案:在iOS中8,UIView的動畫是添加劑,這與規模動畫有一個不幸的結果。

基本上第二個動畫發生了連同第一個動畫。唯一的解決辦法是開始一個新的人之前先明確刪除原始動畫:中

view.layer.transform = view.layer.presentationLayer().transform 
view.layer.removeAllAnimations() 
0

嗨我不太確定你在找什麼,但如果你想讓視圖恢復到原來的規模,你可以添加.Autoreverse標誌。

UIView.animateWithDuration(1, delay: 0, options: .Autoreverse | .Repeat, animations: { 
     myView.layer.transform = CATransform3DMakeScale(0.001, 0.001, 1) 
    }, completion: nil) 

而如果你想串起來的動畫我內UIView.animateKeyframesWithDuration()做

UIView.animateKeyframesWithDuration(2, delay: 0.0, options: nil, animations: { 

     UIView.addKeyframeWithRelativeStartTime(0.0, relativeDuration: 0.5, animations: { 
      // Animation 1 
     }) 

     UIView.addKeyframeWithRelativeStartTime(1, relativeDuration: 0.5, animations: { 
      // Animation 2 
     }) 

    }, completion: nil) 

Animation Gif

+0

對不起,我應該已經更清楚了。在實際的應用程序中,用戶執行一些應該停止原始動畫並將其恢復到原始狀態的動作。 UIViewAnimationOptions.BeginFromCurrentState標誌似乎也沒有任何影響。 – s4y 2015-04-01 21:43:09