学习 CALayer实现,界限、透明度、位置、旋转、缩放组合动画_

首先引入框架:QuartzCore.framework

在头文件声明:CALayer*logoLayer

{

//界限

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

boundsAnimation.fromValue=[NSValuevalueWithCGRect:logoLayer.bounds];

boundsAnimation.toValue=[NSValuevalueWithCGRect:CGRectZero];

//透明度变化

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

opacityAnimation.fromValue=[NSNumbernumberWithFloat:1.0];

opacityAnimation.toValue=[NSNumbernumberWithFloat:0.5];

//位置移动

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

animation.fromValue=[NSValuevalueWithCGPoint:logoLayer.position];

CGPointtoPoint=logoLayer.position;

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

toPoint.x+=180;

animation.toValue=[NSValuevalueWithCGPoint:toPoint];

//旋转动画

CABasicAnimation* rotationAnimation =

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

rotationAnimation.toValue=[NSNumbernumberWithFloat:(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=[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];//缓入缓出

//缩放动画

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

scaleAnimation.fromValue=[NSNumbernumberWithFloat:0.0];

scaleAnimation.toValue=[NSNumbernumberWithFloat:1.0];

scaleAnimation.duration=2.0f;

scaleAnimation.timingFunction=[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];

CAAnimationGroup*animationGroup =[CAAnimationGroupanimation];

animationGroup.duration=2.0f;

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

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

[animationGroupsetAnimations:[NSArrayarrayWithObjects:rotationAnimation,scaleAnimation,nil]];

//将上述两个动画编组

[logoLayeraddAnimation:animationGroupforKey:@"animationGroup"];

}

//去掉所有动画

[logoLayerremoveAllAnimations];

//去掉key动画

[logoLayerremoveAnimationForKey:@"animationGroup"];

  

爱华网本文地址 » http://www.aihuau.com/a/25101017/332302.html

更多阅读

秋天,名词、形容词或者动词 动名词做形容词宾语

秋天,名词、形容词或者动词一:秋天是一个名词漫不经意可以地写写金黄的田野写写秋虫的曼妙看看低垂的果实芬芳的野菊秋天是一个名词是一个多么贴切的代名词啊随手拈来的歌颂或者吟咏玩弄文字游戏,附庸风雅感恩秋天的饱满总能填充越

精选全球最美星空照片,浪漫、令人陶醉 令人陶醉

浪漫的星空总是让人充满遐想,仰望星空,时光仿佛变得静谧,生命仿佛变得透亮,心情变得跟夜空一样透澈。精选全球最美星空照片,浪漫、令人陶醉。关注微信公众号“hahaocn”或“哈好网”,就能每天收到世界各地奇闻趣事,还能和美女小编一对一私

声明:《学习 CALayer实现,界限、透明度、位置、旋转、缩放组合动画_》为网友梦未忘分享!如侵犯到您的合法权益请联系我们删除