2009-12-20
■ [CALayer][CABasicAnimation]レイヤーを使ったアニメーション 
アニメーションの処理方法は3種類あるで書いた2つめの方法。
レイヤーを使った方法だとこんな感じ。
UIImage* image=[UIImage imageNamed:@"image.png"]; //レイヤーの生成 CALayer* layer=[CALayer layer]; [layer setBounds:CGRectMake(0,0,image.size.width,image.size.height)]; [layer setPosition:CGPointMake(60,60)]; [layer setContents:(UIView*)image.CGImage]; [self.view.layer addSublayer:layer]; //レイヤーアニメーションの生成 CABasicAnimation* anime=[CABasicAnimation animationWithKeyPath:@"position"]; anime.duration = 1.0f; anime.autoreverses = YES; anime.repeatCount = 999; CGPoint position = layer.position; anime.fromValue = [NSValue valueWithCGPoint:position]; position.x += 200; anime.toValue = [NSValue valueWithCGPoint:position]; [layer addAnimation:anime forKey:@"anime"];
アニメーションを停止するには、removeAnimationForKey メソッドを使う。
[layer removeAnimationForKey:@"anime"];
コメント