私は、あたかも打たれているかのように、UI要素、つまりコントロールを振動/揺れようとしています。UIアイテムを振動させる最も良い方法は?
CABasicAnimation* rotationXAnimation;
rotationXAnimation = [CABasicAnimation animationWithKeyPath:@"position.y"];
rotationXAnimation.fromValue = [NSNumber numberWithFloat: ((UIControl *) sender).center.y-1.0 ];
rotationXAnimation.toValue = [NSNumber numberWithFloat: ((UIControl *) sender).center.y+1.0 ];
rotationXAnimation.duration = 0.2;
rotationXAnimation.cumulative = NO;
rotationXAnimation.repeatCount = 10.0;
rotationXAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[((UIControl *) sender).layer addAnimation:rotationXAnimation forKey:@"upDownAnimation"];
または私はz軸(-M_PI * 0.02とM_PI * 0.02)を中心に前後に小さなアークによって回転することができる:私は1つの画素、水平方向またはその両方、垂直に振るコアアニメーションを使用することができ:
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.fromValue = [NSNumber numberWithFloat: -M_PI * 0.02 ];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 0.02 ];
rotationAnimation.duration = 0.2;
rotationAnimation.cumulative = NO;
rotationAnimation.repeatCount = 10.0;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[((UIControl *) sender).layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
これらのどれも気に入らない。誰かに良い選択肢がありますか?私は特に、試してみるためにcoolPathのアイデアを感謝します。
ありがとうございます!
アップデート:私は契約および制御を拡大しています
以下は、より良いですが、私はまだ他のアイデアを探しています。
CABasicAnimation* scaleAnimation;
scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.fromValue = [NSNumber numberWithFloat: 0.95 ];
scaleAnimation.toValue = [NSNumber numberWithFloat: +1.05 ];
scaleAnimation.duration = 0.1;
scaleAnimation.cumulative = NO;
scaleAnimation.repeatCount = 10.0;
scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[((UIControl *) sender).layer addAnimation:scaleAnimation forKey:@"scaleAnimation"];
これが唯一であります一方向 - 左右に - 右? – mahboudz
はい。しかし、CGPointである 'position'フィールドをアニメートするのと同じ方法でパスを使用するキーフレームアニメーションを作成することができます。 –