
概述所有核心
动画的动画类都是从 CAAnimation类继承而来 CAAnimation 实现了 CAMediaTiming协议,提供了动画的持续时间,速度,和重复计数CAAnimation 也实现了 CAAction协议。该协议为图层触发一个动画动作提供了提供 标准化响应CATransition 提供了一个图层变化的过渡效果,它能影响图层的整个内容。 动画进行的时候淡入淡出(fade)、
所有核心动画的动画类都是从 CAAnimation类继承而来
CAAnimation 实现了 camediatiming协议,提供了动画的持续时间,速度,和重复计数CAAnimation 也实现了 CAAction协议。该协议为图层触发一个动画动作提供了提供 标准化响应CATransition 提供了一个图层变化的过渡效果,它能影响图层的整个内容。 动画进行的时候淡入淡出(fade)、推(push)、显露(reveal)图层的内容。这些过渡效果可以扩展到 你自己定制的Core Image 滤镜CAAnimationGroup 允许一系列动画效果组合在一起,并行显示动画CAPropertyAnimation是一个抽象的子类,它支持动画的显示图层的关键路径中指定的属性CABasicAnimation 简单的为图层的属性提供修改。CAKeyframeAnimation支持关键帧动画,你可以指定的图层属性的关键路径动画,包括动画的每个阶段的价值,以及关键帧时间和计时功能的一系列值。在 动画运行是,每个值被特定的插入值替代
核心动画的 CAConstraint 类 是一个布局管理器,它可以指定子图层类限制于你指定的约束集合。每个约束(CAConstraint类的实例封装)描述层的几何属性(左,右,顶部或底部的边缘或水平或垂直中心)的关系,关系到其同级之一的几何属性层或superlayer核心动画的图层和 Cocoa 的视图在很大程度上没有一定的相似性,但是他们两者最大的区别是,图层不会直接渲染 到屏幕上 视图的position坐标和anchorPoint有关sublayertransform属性指定的矩阵只会影响图层的子图层,而不会对 图层本身产生影响transform 属性指定的矩阵结合图层的anchorPoint属性作用于图层和图层的子图层上 面旋转的单位采用弧度(radians),而不是角度(degress)。以下两个函数,你可以在 弧度和角度之间切换
[cpp] view plain copy
<span style="Font-size:18px;">CGfloat degreesToradians(CGfloat degrees) {returndegrees * M_PI / 180;}; CGfloat radiansTodegrees(CGfloat radians) {returnradians * 180 / M_PI;};</span> 无法正常运行:
替换的办法是,你必须通过 setValue:forKeyPath:或者valueForKeyPath:方法,具体如下:
copy
<span style="Font-size:18px;">myLayer.transform.rotation.x=0; [myLayer setValue:[NSNumber numberWithInt:0]forKeyPath:@"transform.rotation.x"];</span>
如果一个图层的属性 needsdisplayOnBoundsChange被设置为YES 的时候,当图层的 bounds属性改变的时候,图层的内容将会被重新缓存起来。默认情况下图层的 needsdisplayOnBoundsChange属性值为NO。 给CALayer提供内容 1。包含图片内容的 CGImageRef来显式的设置图层的contents 的属性。 2。指定一个委托,它提供或者重绘内容。 3。继承 CALayer 类重载显示的函数 创建一个委托类实 displayLayer:或 drawLayer:inContext:
copy
<span style="Font-size:18px;">- (voID)displayLayer:(CALayer *)theLayer { // check the value of the layer's state key if ([[theLayer valueForKey:@"state"] boolValue]) { // display the yes image theLayer.contents=[someHelperObjectloadStateYesImage]; } else
{ // display the no image
theLayer.contents=[someHelperObjectloadStateNoImage]; }</span>
如果你必须重绘图层的内容,而不是通过加载图片,那你需要实现drawLayer:inContext:方法。通过委托可以决定哪些内容是需要的并使用CGContextRef来重绘内容。实例重新缓存其内容,可以通过发送以下任何一个方法setNeedsdisplay或setNeedsdisplayInRect:的消息,亦或者设置图层的needsdisplaOnBoundsChange属性为 YESCALayer 的属性 contentsGravity允许你在图层的边界内容修改图层的contents图片的位置或者伸缩值。默认情况下,内容的图像完全填充层的边界,忽视自然的图像宽高比contentsGravity属性值:CABasicAnimation提供了在图层的属性值间简单的插入。CAKeyframeAnimation提供支持关键帧动画。你指定动画的一个图层属性的关键路径,一个表示在动画的每个阶段的价值的数组,还有一个关键帧时间的数组和时间函数。 CATransition提供了一个影响整个图层的内容过渡效果。在动画显示过程中采用淡出(fade)、推出(push)、显露(reveal)图层的内容。常用的过渡效果可以通过提供你自己定制的核心图像滤镜来扩展
copy
<span style="Font-size:18px;">CABasicAnimation *_basicAnimation= [CABasicAnimation animationWithKeyPath:@"opacity"]; _basicAnimation.duration=3.0; _basicAnimation.repeatCount=2; _basicAnimation.autoreverses=YES; _basicAnimation.fromValue=[NSNumber numberWithfloat:1.0]; _basicAnimation.tovalue=[NSNumber numberWithfloat:0.0]; [self.m_imageVIEwBg.layeraddAnimation:_basicAnimation forKey:@"animateOpacity"];</span>
我们可以通过animationWithKeyPath键值对的方式来改变动画
animationWithKeyPath的值:
transform.scale= 比例转换
transform.scale.x =宽的比例转换
transform.scale.y =高的比例转换
transform.rotation.z =平面圆的旋转
opacity = 透明度
margin
zposition
backgroundcolor
cornerRadius
borderWidth
bounds
contents
contentsRect
cornerRadius
frame
hidden
mask
masksToBounds
opacity
position
shadowColor
shadowOffset
shadowOpacity
shadowRadius
copy
<span style="Font-size:18px;"> [self. ui_VIEw.layerremoveAllAnimations]; CABasicAnimation *pulse= [CABasicAnimation animationWithKeyPath:@"transform.scale"]; pulse.timingFunction =[camediatimingFunction functionWithname:kcamediatimingFunctionEaSEOut]; pulse.duration = 0.5 + (rand() % 10) * 0.05; pulse.repeatCount = 1; pulse.autoreverses = YES; pulse.fromValue =[NSNumber numberWithfloat:.8]; pulse.tovalue =[NSNumber numberWithfloat:1.2]; [self.ui_VIEw.layer addAnimation:pulseforKey:nil]; // bounds CABasicAnimation *anim = [CABasicAnimationanimationWithKeyPath:@"bounds"]; anim.duration = 1.f; anim.fromValue =[NSValue valueWithCGRect:CGRectMake(0,10,10)]; anim.tovalue =[NSValue valueWithCGRect:CGRectMake(10,200,200)]; anim.byValue = [NSValuevalueWithCGRect:self. ui_VIEw.bounds]; // anim.tovalue= (ID)[UIcolor redcolor].CGcolor;
// anim.fromValue = (ID)[UIcolorblackcolor].CGcolor;
anim.timingFunction =[camediatimingFunction functionWithname:kcamediatimingFunctionEaseInEaSEOut]; anim.repeatCount = 1; anim.autoreverses = YES; [ui_VIEw.layeraddAnimation:anim forKey:nil]; //cornerRadius
CABasicAnimation*anim2 = [CABasicAnimationanimationWithKeyPath:@"cornerRadius"]; anim2.duration = 1.f; anim2.fromValue =[NSNumber numberWithfloat:0.f]; anim2.tovalue =[NSNumber numberWithfloat:20.f]; anim2.timingFunction =[camediatimingFunction functionWithname:kcamediatimingFunctionEaseInEaSEOut]; anim2.repeatCount = CGfloat_MAX; anim2.autoreverses = YES; [ui_VIEw.layeraddAnimation:anim2 forKey:@"cornerRadius"]; //contents
CABasicAnimation *anim = [CABasicAnimationanimationWithKeyPath:@"contents"]; anim.fromValue =(ID)[UIImageimagenamed:@"1.jpg"].CGImage; anim.tovalue =(ID)[UIImageimagenamed:@"2.png"].CGImage; // anim.byValue = (ID)[UIImageimagenamed:@"3.png"].CGImage;
anim.repeatCount = CGfloat_MAX; [ui_VIEw.layersetShadowOffset:CGSizeMake(2,2)]; [ui_VIEw.layersetShadowOpacity:1]; [ui_VIEw.layersetShadowcolor:[UIcolorgraycolor].CGcolor]; //
CABasicAnimation *anim =[CABasicAnimation animationWithKeyPath:@"shadowcolor"]; anim.tovalue =(ID)[UIcolorredcolor].CGcolor; anim.fromValue = (ID)[UIcolorblackcolor].CGcolor; CABasicAnimation *_anim= [CABasicAnimation animationWithKeyPath:@"shadowOffset"]; _anim.duration = 1.f; _anim.fromValue =[NSValue valueWithCGSize:CGSizeMake(0,0)]; _anim.tovalue =[NSValue valueWithCGSize:CGSizeMake(3,3)]; _anim.timingFunction =[camediatimingFunction functionWithname:kcamediatimingFunctionEaseInEaSEOut]; _anim.repeatCount = CGfloat_MAX; _anim.autoreverses = YES; [ui_VIEw.layeraddAnimation:_anim forKey:nil]; CABasicAnimation *_anim1= [CABasicAnimation animationWithKeyPath:@"shadowOpacity"]; _anim1.duration = 1.f; _anim1.fromValue =[NSNumber numberWithfloat:0.5]; _anim1.tovalue =[NSNumber numberWithfloat:1]; _anim1.timingFunction =[camediatimingFunction functionWithname:kcamediatimingFunctionEaseInEaSEOut]; _anim1.repeatCount = CGfloat_MAX; _anim1.autoreverses = YES; [ui_VIEw.layeraddAnimation:_anim1 forKey:nil]; CABasicAnimation *_anim2= [CABasicAnimation animationWithKeyPath:@"shadowRadius"]; _anim2.duration = 1.f; _anim2.fromValue =[NSNumber numberWithfloat:10]; _anim2.tovalue =[NSNumber numberWithfloat:5]; _anim2.timingFunction =[camediatimingFunction functionWithname:kcamediatimingFunctionEaseInEaSEOut]; _anim2.repeatCount = CGfloat_MAX; _anim2.autoreverses = YES; [ui_VIEw.layeraddAnimation:_anim2 forKey:nil];</span>
CAScrollLayer 对象的滚动区域的范围在它的子图层里面定义。 CAScrollLaye 不提供键盘或鼠标事件处理,也不提供可见的滚动条。 CATextLayer可以方便的从字符串或字符串的内容创建一个图层类的内容 CATiledLayer 允许递增的显示大而复杂的图片 CAEAGLLayer 提供了一个OpenGLES渲染环境 CALayer 的还扩展了 NSkeyvalueCoding的非正式协议,加入默认键值和额外 的结构类型的自动对象包装(CGPoint,CGSize,CGRect,CGAffinetransform和 CAtransform3D)的支持,并提供许多这些结构的关键路径领域的访问
总结
以上是内存溢出为你收集整理的ios 动画基础全部内容,希望文章能够帮你解决ios 动画基础所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
评论列表(0条)