iOS动画

iOS动画有隐式和显示之分。隐式动画指的是,无须创建动画对象,只需改变动画层的属性,让核心动画自己去完成动画效果, 例如(CATransaction)。显示动画指的是,需要自己创建和管理动画对象,并且将它们应用到动画层,才能显示动画效果。


CGRectInset: Returns a rectangle that is smaller or larger than the source rectangle, with the same center point.

创建一个矩形框, 以原先frame的center为中心, 可做绕一个圈转的动画:

CGMutablePathRefcurvedPath =CGPathCreateMutable();

CGRectcircleContainer =CGRectInset(self.frontView.frame,self.frontView.bounds.size.width/2-13,self.frontView.bounds.size.width/2-13);

CGPathAddEllipseInRect(curvedPath,NULL, circleContainer);

CAKeyframeAnimation*pathAnimation = [CAKeyframeAnimationanimationWithKeyPath:@"position"];

pathAnimation.calculationMode=kCAAnimationPaced;

pathAnimation.fillMode=kCAFillModeForwards;

pathAnimation.removedOnCompletion=NO;

pathAnimation.repeatCount=INFINITY;

pathAnimation.timingFunction= [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionLinear];

pathAnimation.duration=5.0;

pathAnimation.path= curvedPath;

CGPathRelease(curvedPath);


CAKeyframeAnimation关键帧动画也可做一系列形变:

CAKeyframeAnimation*scaleY = [CAKeyframeAnimationanimationWithKeyPath:@"transform.scale.y"];

scaleY.duration=1.5;

scaleY.values=@[@1.0,@1.1,@1.0];

scaleY.keyTimes=@[@0.0,@0.5,@1.0];

scaleY.repeatCount=INFINITY;

scaleY.autoreverses=YES;

scaleX.timingFunction= [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];

[self.frontView.layeraddAnimation:scaleYforKey:@"scaleYAnimation"];

同理scaleX

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容