この記事では、私はブログを学んでいます
http://www.cnblogs.com/kenshincui/p/3972100.html#autoid-3-2-0
アニメーション
移動物体の実際の開発は、多くの場合、複雑な動きで、単一のプロパティの動きが比較的小さいが、それはアニメーションやキーフレームアニメーションの基礎であるかどうか(場合にのみ、プロパティのアニメーションコントロールアニメーション設定されている設定可能なだけでアニメーションの属性ごとに一度そう)、組み合わせた複数のプロパティを作成する必要があり、映画などの複雑なモーション・アニメーションを実行します。アニメーションの12種類の組み合わせにも対処しやすいが、より多くの制御組成物に非常に煩雑アニメーションなる傾向ができるため、アニメーション基が生じる状況に基づいています。アニメーションは、アニメーションのシリーズとの組み合わせで、アニメーションのアニメーショングループへのすべてのアドオンがアニメーショングループによって制御され、そのような行動の一般的なアニメーションのすべてのタイプのために単独で統一さを設定し、アニメーショングループを置くことなく、制御することができます各アニメーションは、複雑なアニメーションを構築するために協力し、同時に実行することができます。
アニメーションは、使用に複雑ではない、あなたが最初に(基礎アニメーションもキーフレームアニメーションすることができすることができます)1つのムービーを作成し、アニメーショングループごとにアニメーションを追加する別のレイヤーにアニメーションを追加するための最後のグループです。
キーフレームアニメーション、パスアニメーション効果の前部を、ルックスは非常に滑らかな、しかし、花自体は、それが結合させアニメーション全体の外観は、より調和のとれた滑らかの回転アニメーションとアニメーションパスのキーフレームアニメーションの基礎部分であるかもしれない回転運動、ではないが。
// //アニメーション //アニメーション // //謙信崔ON 14-3-22によって作成されます。 //著作権(C)2014インディアンキュイ謙信。すべての権利を保有。 // の#import "KCMainViewController.h" @ インターフェイスKCMainViewController(){ CALayerの* _layer; } @end @implementation KCMainViewController - (ボイド)のviewDidLoad { [スーパーのviewDidLoad]; //設定された背景(基点画像層におけるこの事実に注意) UIImage backgroundImageの* = [UIImage imageNamed:@ 「背景.JPG " ]; self.view.backgroundColor = [UIColor colorWithPatternImage:backgroundImageの]; //カスタム層 _layer = [CALayerのALLOC] INIT]。 _layer.bounds = CGRectMake(0、0、10、20)。 _layer.position = CGPointMake(50、150)。 _layer.contents =(ID)[UIImage imageNamed:@ "petal.png" ] .CGImage。 [self.view.layer addSublayer:_layer]。 //创建动画 [自己groupAnimation]。 } の#pragma マーク基础旋转动画 - (CABasicAnimation *)rotationAnimation { CABasicAnimation * basicAnimation = [CABasicAnimation animationWithKeyPath:@ "transform.rotation.z" ]。 CGFloat toValueの= M_PI_2 * 3。 basicAnimation.toValue =〔のNSNumber numberWithFloat:M_PI_2 * 3]。 // basicAnimation.duration = 6.0; basicAnimation.autoreverses = 真; basicAnimation.repeatCount = HUGE_VALF。 basicAnimation.removedOnCompletion = NO; [basicAnimationのsetValue:[のNSNumber numberWithFloat:toValueの] forKey:@ "KCBasicAnimationProperty_ToValue" ]; 返すbasicAnimationを。 } の#pragma マーク关键帧移动动画 - (CAKeyframeAnimation *)translationAnimation { CAKeyframeAnimation * keyframeAnimation = [CAKeyframeAnimation animationWithKeyPath:@ "位置" ]。 するCGPointなendPoint = CGPointMake(55、400)。 CGPathRefパス= CGPathCreateMutable()。 CGPathMoveToPoint(パス、NULL、_layer.position.x、_layer.position.y)。 CGPathAddCurveToPoint(パス、NULL、160、280、-30、300、endPoint.x、endPoint.y)。 keyframeAnimation.path =パス。 CGPathRelease(パス); [keyframeAnimationのsetValue:[NSValue valueWithCGPoint:エンドポイント] forKey:@ "KCKeyframeAnimationProperty_EndPosition" ]; 戻りkeyframeAnimation; } の#pragma マークアニメーションを作成 - (ボイド){groupAnimation .. 1 //アニメーション作成 CAAnimationGroupを使うを* animationGroup = [アニメーションCAAnimationGroupを使う]; //セット2グループとアニメーションの他の属性 CABasicAnimation basicAnimation * = [自己rotationAnimation]; CAKeyframeAnimation keyframeAnimation * = [自己translationAnimation]; animationGroup.animations = @ [basicAnimation、keyframeAnimation]; 。animationGroup デリゲート=自己; = 10.0 animationGroup.duration; //アニメーション時間、アニメーション映画のアニメーションのセットは、すでに、もはや有効にするに設定されていない属性場合 animationGroup.beginTime CACurrentMediaTime =()+ 5; // 5秒の遅延実行 3層に添加されます@。アニメーション [addAnimation _layer:animationGroup forKey:なし]; } の#pragma マーク-プロキシ方式 の#pragma マークアニメーション完了 - (ボイド)animationDidStop:(CAAnimation *)Animの仕上がり:フラッグ{IN(BOOL) CAAnimationGroupを使うanimationGroup * =(CAAnimationGroupを使う*)Animの; CABasicAnimation * basicAnimation animationGroup.animations = [0]; CAKeyframeAnimation * keyframeAnimation animationGroup.animations = [1] CGFloat toValueの= [[basicAnimation valueForKey:@ ] Oに従ってFloatValue]。"KCBasicAnimationProperty_ToValue" するCGPointなendPoint = [[keyframeAnimation valueForKey:@ "KCKeyframeAnimationProperty_EndPosition" ] CGPointValue]。 [開始CATransaction]。 [CATransaction setDisableActions:YES]。 //设置动画最终状态 _layer.position =なendPoint。 _layer.transform = CATransform3DMakeRotation(toValueの、0、0、1)。 [コミットCATransaction]。 } @end