我有,当按下按钮并保持在屏幕上运行的的UIImageView。 当按下按钮是改变的UIImageView的UIImage的,当按钮被放过我将其更改为原来的UIImage。 当曾经的图像变回它弹回的图像开始的位置。
当按下按钮,该计时器被称为:
//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];
这就是所谓的在正在举行的按钮停止:
- (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"];
}
我需要的图像添加到动画的变化? 如果是的话怎么样? 我真的糊涂。