私はアニメーションプロジェクトを実装しています。画像 wheel.png があります。CAKeyFrameAnimation を使用してこの画像を回転するにはどうすればよいですか。私は既に CABasicAnimation を使用してこの画像を回転させています。
1439 次
1 に答える
2
これは、回転するホイールを作成する方法を段階的に示している ray のサイトのチュートリアルです。回転アニメーションのサンプルコードを確認してください。それがあなたが探しているものかもしれません。
http://www.raywenderlich.com/9864/how-to-create-a-rotating-wheel-control-with-uikit
それは使用しますUIKit
が、あなたはアイデアを得る。
編集:
これは、画像を継続的に回転させるサンプルコードCAKeyFrameAnimation
です。これをいじって、好きなことを実行できます。これがお役に立てば幸いです。
UIImageView *tempView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 80, 80)];
tempView.image = [UIImage imageNamed:@"Icon"];
tempView.backgroundColor = [UIColor redColor];
[self.view addSubview:tempView];
const NSUInteger rotations = 10;
const NSTimeInterval duration = 5;
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];
CGFloat touchUpStartAngle = 0;
CGFloat touchUpEndAngle = (M_PI);
CGFloat angularVelocity = (((2 * M_PI) * rotations) + M_PI) / duration;
anim.values = @[@(touchUpStartAngle), @(touchUpStartAngle + angularVelocity * duration)];
anim.duration = duration;
anim.autoreverses = NO;
anim.delegate = self;
anim.repeatCount = 1;
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[tempView.layer addAnimation:anim forKey:@"test"];
tempView.transform = CGAffineTransformMakeRotation(touchUpStartAngle + (touchUpEndAngle));
于 2013-06-19T13:39:32.310 に答える