【转】让对象沿着某条路径移动的动画效果

来源:互联网 发布:淘宝网销售排行 编辑:程序博客网 时间:2024/05/18 23:24

让对象沿着某条路径移动的动画效果,摘自: http://snipplr.com/view.php?codeview&id=49869

CAKeyframeAnimation *bounceAnimation=[CAKeyframeAnimation animationWithKeyPath:@"position"];bounceAnimation.duration=timeForAnimation; CGMutablePathRef thePath=CGPathCreateMutable(); CGPathMoveToPoint(thePath, NULL, 160, 514);
CGPathAddLineToPoint(thePath, NULL, 160, 350);CGPathAddLineToPoint(thePath, NULL, 160, 406);bounceAnimation.path=thePath;CGPathRelease(thePath); CABasicAnimation *mainAnimation=[CABasicAnimation animationWithKeyPath:@"transform"];mainAnimation.removedOnCompletion=YES;mainAnimation.duration=timeForAnimation;mainAnimation.toValue=[NSValue valueWithCATransform3D:CATransform3DIdentity];  CAAnimationGroup *theGroup=[CAAnimationGroup animation];theGroup.delegate=self;theGroup.duration=timeForAnimation;theGroup.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];theGroup.animations=[NSArray arrayWithObjects:bounceAnimation,mainAnimation,nil];[imgV.layer addAnimation:theGroup forKey:@"sagar"];imgV.center=CGPointMake(160, 406);imgV.transform=CGAffineTransformIdentity;
原创粉丝点击