2012-02-03 113 views
2

我正在使用此代碼刪除動畫我的UIView刪除按鈕刪除按鈕按下。 下面的代碼:如何將UIBezierPath與CoreAnimation一起使用?

UIBezierPath *movePath = [UIBezierPath bezierPath]; 
      [movePath moveToPoint:icon.center]; 
      [movePath addQuadCurveToPoint:senderView.center 
          controlPoint:CGPointMake(senderView.center.x, icon.center.y)]; 

      CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
      moveAnim.path = movePath.CGPath; 
      moveAnim.removedOnCompletion = YES; 

      CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"]; 
      scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity]; 
      scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]; 
      scaleAnim.removedOnCompletion = YES; 

      CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"]; 
      opacityAnim.fromValue = [NSNumber numberWithFloat:1.0]; 
      opacityAnim.toValue = [NSNumber numberWithFloat:0.1]; 
      opacityAnim.removedOnCompletion = YES; 

      CAAnimationGroup *animGroup = [CAAnimationGroup animation]; 
      animGroup.animations = [NSArray arrayWithObjects:moveAnim, scaleAnim, opacityAnim, nil]; 
      animGroup.duration = 2.0; 
      [icon.layer addAnimation:animGroup forKey:nil]; 

這實際上動畫UIView的給刪除按鈕,但它再次顯示在同一個地方了之後。

回答

0

將每個動畫的removedOnCompletion設置爲NO及其fillModekCAFillModeForwards

+0

嘗試過,但動畫結束後仍然顯示UIView。 – Ashutosh 2012-02-03 18:57:53

+0

嗯。也許動畫組需要相同的設置?它可能會凌駕其子動畫的屬性。 – 2012-02-03 19:39:42

+0

無處不在。就像它在它開始的同一個地方停下來一樣。 – Ashutosh 2012-02-03 19:55:45

0

嘗試改變不透明度動畫:

CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];

,然後設置動畫組的removeOnCompletionNO及其fillModekCAFillModeForwards像諾亞威瑟斯龐建議。

3

動畫適用於表示層,而不是模型層。您需要將更改應用於兩者。這是一種奇特的說法,當你做動畫時,你也需要直接設置它。

 ... 
     [icon.layer setPosition:CGPointMake(senderView.center.x, icon.center.y)]; 
     [icon.layer setTransform:CATransform3DMakeScale(0.1, 0.1, 1.0)]]; 
     [icon.layer setAlpha:0.1]; 

(請注意,您可能要動畫視圖的center這裏,而不是層的position。)

章如果你想的複雜細節的iOS 5 Programming Pushing the Limits 7對本頁面和頁面。下面是關於removedOnCompletion部分:

有時候你看到的人建議設置removedOnCompletion NO和在fillMode到kCAFillModeBoth。這不是一個好的解決方案。它基本上使動畫永遠持續下去,這意味着模型層永遠不會更新。如果您詢問物業的價值,您會繼續看到模型價值,而不是您在屏幕上看到的。如果您之後嘗試隱式設置屬性的動畫效果,則CAAnimation仍在運行,所以無法正常工作。如果您通過將動畫替換爲具有相同名稱的另一個動畫來移除該動畫,則調用removeAnimationForKey:或removeAllAnimations,舊值會恢復。最重要的是,這浪費了記憶。

相關問題