技术开发 频道

新手必读:iPhone SDK示例代码解析

  Animation: 移动一个对象

  让一个对象在屏幕上显示成一个移动轨迹。注意:这个Animation叫"fire and forget"。也就是说编程人员不能够在animation过程中获得任何信息(比如当前的位置)。假如你需要这个信息的话,那么就需要通过animate和定时器在必要的时候去调整x&y坐标。

CABasicAnimation *theAnimation;    
theAnimation
=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
theAnimation.duration
=1;
theAnimation.repeatCount
=2;
theAnimation.autoreverses
=YES;
theAnimation.fromValue
=[NSNumber numberWithFloat:0];
theAnimation.toValue
=[NSNumber numberWithFloat:-60];
[view.layer addAnimation:theAnimation forKey:@
"animateLayer"];
0
相关文章