动画

首先引入框架:QuartzCore.framework

在头文件声明:CALayer *logoLayer

{

//界限

CABasicAnimation *boundsAnimation = [CABasicAnimationanimationWithKeyPath:@"bounds"];

boundsAnimation.fromValue = [NSValue valueWithCGRect:logoLayer.bounds];

boundsAnimation.toValue = [NSValue valueWithCGRect:CGRectZero];

//透明度变化

CABasicAnimation *opacityAnimation = [CABasicAnimationanimationWithKeyPath:@"opacity"];

opacityAnimation.fromValue = [NSNumber numberWithFloat:1.0];

opacityAnimation.toValue = [NSNumber numberWithFloat:0.5];

//位置移动

CABasicAnimation *animation  = [CABasicAnimation animationWithKeyPath:@"position"];

animation.fromValue =  [NSValue valueWithCGPoint:logoLayer.position];

CGPoint toPoint =logoLayer.position;

toPoint.x += 180;

animation.toValue = [NSValue valueWithCGPoint:toPoint];

//旋转动画

CABasicAnimation* rotationAnimation =

[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];//"z"还可以是“x”“y”,表示沿z轴旋转

rotationAnimation.toValue = [NSNumber numberWithFloat:(2 * M_PI) * 3];

// 3 is the number of 360 degree rotations

// Make the rotation animation duration slightly less than the other animations to give it the feel

// that it pauses at its largest scale value

rotationAnimation.duration = 2.0f;

rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];//缓入缓出

//缩放动画

CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];

scaleAnimation.fromValue = [NSNumber numberWithFloat:0.0];

scaleAnimation.toValue = [NSNumber numberWithFloat:1.0];

scaleAnimation.duration = 2.0f;

scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

CAAnimationGroup *animationGroup = [CAAnimationGroup animation];

animationGroup.duration = 2.0f;

animationGroup.autoreverses = YES;//是否重播,原动画的倒播

animationGroup.repeatCount =NSNotFound;//HUGE_VALF;     //HUGE_VALF,源自math.h

[animationGroup setAnimations:[NSArray arrayWithObjects:rotationAnimation, scaleAnimation, nil]];

//将上述两个动画编组

[logoLayer addAnimation:animationGroup forKey:@"animationGroup"];

}

//去掉所有动画

[logoLayer removeAllAnimations];

//去掉key动画

[logoLayer removeAnimationForKey:@"animationGroup"];

1.动画讲解,非常详细,基础

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

推荐阅读更多精彩内容