0

CABasicAnimationを使用して画像を移動していますが、タッチイベントのrectが古い位置のままであることに気付きました-rectを更新して、間違った場所に登録されないようにするにはどうすればよいですか?

CABasicAnimation *theAnimation; 
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
theAnimation.duration=0.3;
theAnimation.repeatCount=0;
theAnimation.fillMode = kCAFillModeForwards;
theAnimation.removedOnCompletion = NO;
theAnimation.autoreverses=NO;
theAnimation.fromValue=[NSNumber numberWithFloat:0];
theAnimation.toValue=[NSNumber numberWithFloat:-rect.size.width*0.9];
[self.layer addAnimation:theAnimation forKey:@"animateLayer"];
4

1 に答える 1

1

この場合、ではなく、のTouchImageViewサブクラスを移動する必要があります。後者は下位レベルの描画面ですが、タッチイベントなどを処理するものではありません。UIImageViewself.layer

iPadから:アニメーションを使用してUIViewを移動し、次に元に戻しtranslationます。これは、実行中にプロパティをアニメーション化するいくつかの適応コードです。

CGFloat moveX = -rect.size.width*0.9;
CGFloat moveY = 0;

[UIView beginAnimations: @"Move View" context:nil];
[UIView setAnimationDuration: 0.3 ];
self.transform = CGAffineTransformMakeTranslation(moveX,moveY);
[UIView commitAnimations];

ただし、ビューのフレームを変更するだけで、これを単純化できるはずです。

CGRect newFrame = self.frame;
newFrame.x -=rect.size.width*0.9;

[UIView beginAnimations: @"Move View" context:nil];
[UIView setAnimationDuration: 0.3 ];
self.frame = newFrame;
[UIView commitAnimations];
于 2012-07-05T11:26:19.557 に答える