CABasicAnimation に問題があります。その投稿に似ています: CABasicAnimation 回転は元の位置に戻ります
だから、私はtouchMoveで回転するuiimageviewを持っています。「慣性のアニメーション」を行う touchEnd メソッドを呼び出します。
-(void)animationRotation: (float)beginValue
{
CABasicAnimation *anim;
anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
anim.duration = 0.5;
anim.repeatCount = 1;
anim.fillMode = kCAFillModeForwards;
anim.fromValue = [NSNumber numberWithFloat:beginValue];
[anim setDelegate:self];
anim.toValue = [NSNumber numberWithFloat:(360*M_PI/180 + beginValue)];
[appleView.layer addAnimation:anim forKey:@"transform"];
CGAffineTransform rot = CGAffineTransformMakeRotation(360*M_PI/180 + beginValue);
appleView.transform = rot;
}
このアニメーションは問題なく動作しますが、animationRotation が終了する前に touchBegan を呼び出すと、回転角度は beginValue になります。現在の回転角度が必要です。実験として、私はメソッドを宣言します
-(vod) animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
NSLog(@"Animation finished!");
}
そしてそれは働いているようです。しかし、animationDidStop で UIImageView の角度または CGAffineTransform の値を取得する方法がわかりません。することさえ可能ですか?ありがとう。