2013-02-11 43 views
0

Im新增核心动画。每次我调用动画时,图像都会从其位置移动到屏幕的左上角,然后移动,然后返回到原始位置。如何让图像移动50个单位,停止,然后重复,如果再次按下按钮。 代码:动画调用后UIImage视图重置

-(IBAction)preform:(id)sender{ 

CGPoint point = CGPointMake(50, 50); 

CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"position"]; 
anim.fromValue = [NSValue valueWithCGPoint:point]; 
anim.toValue = [NSValue valueWithCGPoint:CGPointMake(point.x + 50, point.y)]; 
anim.duration = 1.5f; 
anim.repeatCount =1; 
anim.removedOnCompletion = YES; 
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; 
[imView.layer addAnimation:anim forKey:@"position"]; 

} 

回答

1

对于你的情况,你可以跳过重CA机器和使用块动画

// Your image is at starting position 
[UIView animateWithDuration:1.5 animations:^{ 
     CGRect newFrame = CGRectOffset(imView.frame, 50, 0); 
     imView.frame = newFrame; 
    }]; 

但是,如果你想知道如何处理这个“弹回”正常,检查this url