2016-11-19 3 views
1

私は、Safariのドックに飛んでいるダウンロードに似たカーブしたパスでアニメートしたいUIViewを持っています。 Core GraphicsとCore Animationが関係していると私は確信しています。私が最後に見つけた答えは2011年からのもので、iOS 6で廃止された機能を使用しているためそのまま実行できません。前もって感謝します。カーブを使ったパスアニメーションコアグラフィック

答えて

0

CAKeyframeAnimationには、アニメーション化するパスプロパティが必要です。

あなたは私が後でスウィフト3例を投稿することができ、それを把握できない場合の例では、そのMac用とその目的C.ここにもあります: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Animation_Types_Timing/Articles/PropertyAnimations.html

+0

私はあまりにもObjective-Cのを知っているので、私はそれをチェックアウトします –

0

のは、カーブポイントを見てみましょうP1、P2、はp3、p4およびp5,&は、隣接ポイントの各ペアの中間点を見つけます。 p1とp2の中間点をm1とします。 m2、m3、m4についても同様です。

  • コントロールポイントとしてp2をポイントm2に追加します。
  • コントロールポイントとしてp3を使用してポイントm3にクワッドカーブを追加します。
  • p4を制御点としてポイントm4にクワッドカーブを追加します。

コード:

CGFloat screenWidth = self.view.frame.size.width; 
CGFloat screenHeight = self.view.frame.size.height; 

UIView *aniView = [[UIView alloc] initWithFrame:CGRectMake(50, screenHeight, 50, 50)]; 
[aniView setBackgroundColor:[UIColor redColor]]; 
aniView.layer.cornerRadius = 25.0; 
[self.view addSubview:aniView]; 


UIBezierPath *movePath = [UIBezierPath bezierPath]; 
[movePath moveToPoint:aniView.center]; 
[movePath addQuadCurveToPoint:CGPointMake(screenWidth-50,screenHeight-50) 
       controlPoint:CGPointMake(screenWidth/2,screenHeight-150)]; 
CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
moveAnim.path = movePath.CGPath; 
moveAnim.removedOnCompletion = YES; 
CAAnimationGroup *animGroup = [CAAnimationGroup animation]; 
animGroup.animations = [NSArray arrayWithObjects:moveAnim, nil]; 
animGroup.duration = 2.0; 

[CATransaction begin]; { 
    [CATransaction setCompletionBlock:^{ 
     [aniView.layer removeAllAnimations]; 
     [aniView removeFromSuperview]; 
    }]; 

    [aniView.layer addAnimation:animGroup forKey:nil]; 

} [CATransaction commit]; 

上記のコードをコピーし、過去のいくつかの方法にしてメソッドを呼び出してみてください...

関連する問題