Animation Schnappt zurück, wenn das UIImage geändert wird

Ich habe eine UIImageView, die über den Bildschirm läuft, wenn eine Taste gedrückt und gehalten wird. Wenn die Taste gedrückt wird, ändert sich das UIImage der UIImageView und wenn die Taste losgelassen wird, ändere ich es auf das ursprüngliche UIImage. Wenn sich das Bild ändert, rastet es an der Stelle ein, an der das Bild gestartet wurde.

Dieser Timer wird aufgerufen, wenn die Taste gedrückt wird:

//This is the image that changes when the button is pressed.
imView.image = image2;
runTimer = [NSTimer scheduledTimerWithTimeInterval:0.04
                                            target:self
                                          selector:@selector(perform)
                                          userInfo:nil
                                           repeats:YES];

Dies wird aufgerufen, wenn die Taste nicht mehr gedrückt wird:

- (IBAction)stopPerform:(id)sender{
   [runTimer invalidate];

   //THIS IS WHAT SNAPS THE ANIMATION BACK:
   //Without this the animation does not snap back
   imView.image = image1;
}

- (void)performRight{

 CGPoint point0 = imView.layer.position;
 CGPoint point1 = { point0.x + 4, point0.y };

 CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"position.x"];
 anim.fromValue    = @(point0.x);
 anim.toValue  = @(point1.x);
 anim.duration   = 0.2f;
 anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

 // First we update the model layer's property.
 imView.layer.position = point1;

 // Now we attach the animation.
 [imView.layer  addAnimation:anim forKey:@"position.x"];
}

Muss ich die Änderung in Bildern zur Animation hinzufügen? Wenn das so ist, wie? Ich bin wirklich verwirrt.

Antworten auf die Frage(1)

Ihre Antwort auf die Frage