iphone中CABasicAnimation和UIView动画的区别[转]
关于UIView动画:
- [UIView beginAnimations:@"zoom out" context:nil];
- [UIView setAnimationDuration:1.f];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
- cover.transform = CGAffineTransformMakeScale(9.25,7.05);
- cover.center = CGPointMake(430, 512);
- [UIView commitAnimations]
UIView动画是应用在一个view上面的。
关于CABasicAnimation动画:
- - (CAAnimation *)animationMove:(CGPoint)rootCenter
- {
- CABasicAnimation *animationMove
- = [CABasicAnimation animationWithKeyPath:@"position"];
- animationMove.duration = 1;
- animationMove.autoreverses = NO;
- // animationMove.delegate = self;
- animationMove.removedOnCompletion = NO;
- animationMove.fillMode = kCAFillModeForwards;
- animationMove.fromValue = [NSValue valueWithCGPoint:self.oldCoverCenter];
- animationMove.toValue =[NSValue valueWithCGPoint:rootCenter];
- return animationMove;
- }
CABasicAnimation动画是应用在一个layer上面的。
注:
1,把一个image放在一个view的layer上来放大的时候,如果用UIView来做,图片不会太多的失真和闪烁的效果,但是用CABasicAnimation来做失真和闪烁现象会很严重,效果很不好。
2,做 动画的叠加效果 很简单,只要把各自的动画放在一起就可以了。请看这个效果:一本书边移动到屏幕中间,边放大,边打开封面的效果。
- [imageLayer addAnimation:[self animationOpen] forKey:@"Open"];
- [UIView beginAnimations:@"zoom out" context:nil];
- [UIView setAnimationDuration:1.f];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
- cover.transform = CGAffineTransformMakeScale(5.5,5.5);
- cover.center = CGPointMake(629, 384);
- [UIView commitAnimations];
- - (CAAnimation *)animationOpen
- {
- CABasicAnimation *animationOpen
- = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
- animationOpen.duration = 1;
- animationOpen.autoreverses = NO;
- animationOpen.delegate = self; //然后执行真正地打开书的内容
- animationOpen.removedOnCompletion = NO;
- animationOpen.fillMode = kCAFillModeForwards;
- animationOpen.fromValue = [NSNumber numberWithFloat:-M_PI/5];
- animationOpen.toValue = [NSNumber numberWithFloat:-M_PI/1.5];
- return animationOpen;
- }