打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
【学习】CALayer实现,界限、透明度、位置、旋转、缩放组合动画

 

首先引入框架:QuartzCore.framework

在头文件声明:CALayer *logoLayer

{

//界限

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

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

boundsAnimation.toValue =[NSValue valueWithCGRect:CGRectZero];


//透明度变化

CABasicAnimation *opacityAnimation =[CABasicAnimation animationWithKeyPath:@"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 otheranimations 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"];


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
iOS动画(一)拍电影与CABasicAnimation
ios常用的几个动画代码
< iOS >CABasicAnimation用法
iOS 实现渐变背景动画效果的Switch
IOS开发UI篇
CABasicAnimation的基本使用方法(移动·旋转·放大·缩小)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服