iphone中CABasicAnimation和UIView动画的区别[转]

关于UIView动画:

  1. [UIView beginAnimations:@"zoom out" context:nil];
  2. [UIView setAnimationDuration:1.f];
  3. [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
  4. cover.transform = CGAffineTransformMakeScale(9.25,7.05);
  5. cover.center = CGPointMake(430512);
  6. [UIView commitAnimations]

UIView动画是应用在一个view上面的。

关于CABasicAnimation动画:

  1. - (CAAnimation *)animationMove:(CGPoint)rootCenter
  2. {
  3.     CABasicAnimation *animationMove
  4.     = [CABasicAnimation animationWithKeyPath:@"position"];
  5.     animationMove.duration = 1;
  6.     animationMove.autoreverses = NO;
  7. //    animationMove.delegate = self;
  8.     animationMove.removedOnCompletion = NO;
  9.     animationMove.fillMode = kCAFillModeForwards;
  10.     animationMove.fromValue = [NSValue valueWithCGPoint:self.oldCoverCenter];
  11.     animationMove.toValue =[NSValue valueWithCGPoint:rootCenter];
  12.  
  13.     return animationMove;
  14. }

CABasicAnimation动画是应用在一个layer上面的。

注:
1,把一个image放在一个view的layer上来放大的时候,如果用UIView来做,图片不会太多的失真和闪烁的效果,但是用CABasicAnimation来做失真和闪烁现象会很严重,效果很不好。
2,做 动画的叠加效果 很简单,只要把各自的动画放在一起就可以了。请看这个效果:一本书边移动到屏幕中间,边放大,边打开封面的效果。

  1. [imageLayer addAnimation:[self animationOpen] forKey:@"Open"];
  2. [UIView beginAnimations:@"zoom out" context:nil];
  3. [UIView setAnimationDuration:1.f];
  4. [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
  5. cover.transform = CGAffineTransformMakeScale(5.5,5.5);
  6. cover.center = CGPointMake(629384);
  7. [UIView commitAnimations];
  8.  
  9. - (CAAnimation *)animationOpen
  10. {
  11.     CABasicAnimation *animationOpen
  12.     = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
  13.     animationOpen.duration = 1;
  14.     animationOpen.autoreverses = NO;
  15.     animationOpen.delegate = self;  //然后执行真正地打开书的内容
  16.     animationOpen.removedOnCompletion = NO;
  17.     animationOpen.fillMode = kCAFillModeForwards;
  18.     animationOpen.fromValue = [NSNumber numberWithFloat:-M_PI/5];
  19.     animationOpen.toValue = [NSNumber numberWithFloat:-M_PI/1.5];
  20.  
  21.     return animationOpen;
  22. }
posted @ 2012-03-26 18:34  Ethan_村长  阅读(2364)  评论(0编辑  收藏  举报