iOSアニメーションのCALayerアニメーション
4221 ワード
CALayerアニメーションCAPropertyAnimation抽象クラス一般的には、アニメーションCABasicAnimationベースのアニメーション変更サイズの回転を実現するために、次の2つの方法を使用します.CAKeyframeAnimationは、アニメーションのセットを実行するときにバックグラウンドカラーを使用するなど、主にトラックごとに位置を変更します.
CABasicAnimation基本手順1.基本アニメーション//回転を例に
2属性の変化をどの値に設定するか
3アニメーション時間の繰り返し回数を設定する
4.設定したアニメーションをlayerに追加する
CAKeyframeAnimation基本手順//揺れを例に1.アニメーションの作成
2.対象となる
3.valuesを割り当てるには配列が必要です
4.アニメーション時間の設定
5.アニメーションの追加
};
CABasicAnimation基本手順1.基本アニメーション//回転を例に
// keyPath
// keyPath
// transform.rotation.x
// X X
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];
2属性の変化をどの値に設定するか
// tovalue NSNumber NSValue
animation.toValue = [NSNumber numberWithFloat:0. 5];
3アニメーション時間の繰り返し回数を設定する
animation.duration = 1;
animation.repeatDuration = 3;
4.設定したアニメーションをlayerに追加する
// 2
[self.MyView.layer addAnimation:animation forKey:@"transform.rotation.x"];
CAKeyframeAnimation基本手順//揺れを例に1.アニメーションの作成
NSStringFromCGPoint(self.MyView.layer.position));
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position.x"];
2.対象となる
NSNumber *num1 = [NSNumber numberWithFloat:self.MyView.layer.position.x - 50];
NSNumber *num2 = [NSNumber numberWithFloat:self.MyView.layer.position.x ];
NSNumber *num3 = [NSNumber numberWithFloat:self.MyView.layer.position.x + 50];
NSNumber *num4 = [NSNumber numberWithFloat:self.MyView.layer.position.x ];
NSNumber *num5 = [NSNumber numberWithFloat:self.MyView.layer.position.x - 50];
3.valuesを割り当てるには配列が必要です
animation.values = @[num1, num2, num3, num4, num5];
4.アニメーション時間の設定
animation.duration = 0.5;
animation.repeatCount = 4;
5.アニメーションの追加
[self.MyView.layer addAnimation:animation forKey:@"position"];
};