UIImageView動畫:顯示了something在屏幕上移動。

注:這種類型的動畫是“開始後不處理” -你不能獲取任何有關物體在動畫中的信息(如當前的位置) 。如果您需要此信息,您會手動使用定時器去調整動畫的X和Y座標

這個需要導入QuartzCore.framework

 

NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

CABasicAnimation *theAnimation;

theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];

//Creates and returns an CAPropertyAnimation instance for the specified key path.

//parameter:the key path of the property to be animated

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"];

[pool drain];

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章