CAAnimation的一些坑

CAAnimation动画实际是加在layer上,在执行完毕之后,动画效果就会消失,若要得到动画后的效果,需要加上两个属性

CGRect frame = view.frame;

view.transform = CGAffineTransformMakeTranslation(0.0, -CGRectGetMaxY(frame));

CABasicAnimation *trans = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];

trans.byValue = [NSNumber numberWithFloat:CGRectGetMaxY(frame)];

trans.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

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

scale.fromValue = @0.0;

scale.toValue = @1.0;

scale.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

CAAnimationGroup *group = [CAAnimationGroup animation];

group.animations = @[trans,scale];

group.duration = 0.3;

group.beginTime = CACurrentMediaTime() + animationOffset;

//动画执行后的状态模式

group.fillMode = kCAFillModeForwards;

//动画执行后不删除该状态

group.removedOnCompletion = NO;

group.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];


//设置动画的代理需要在加到layer之前

if (completion) {

//动画的delegate为强引用

group.delegate = self;//此delegate为strong

_CurrentComplete = completion;

}

[view.layer addAnimation:group forKey:kTranslateAndscale];



动画的代理为强引用,所以可能会引起retain circle

如果动画

group.removedOnCompletion = NO;

为yes时,此时不存在问题,但是当removedOnCompletion = NO;时,此时应该在视图移除之前移除其动画。

CASpringAnimation的坑

在使用其他动画时

group.fillMode = kCAFillModeForwards;

//动画执行后不删除该状态

group.removedOnCompletion = NO;

动画执行完毕都会得到我们想要的结果,但是设置完CASpringAnimation的这两个属性后,动画执行完毕,layer属性的变化往往的不到我们想要的结果

/* The mass of the object attached to the end of the spring. Must be greater

than 0. Defaults to one. */

@property CGFloat mass;// 质量

/* The spring stiffness coefficient. Must be greater than 0.

* Defaults to 100. */

@property CGFloat stiffness;//刚度,刚度是指材料或结构在受力时抵抗弹性变形的能力

/* The damping coefficient. Must be greater than or equal to 0.

* Defaults to 10. */

@property CGFloat damping;//阻尼

/* The initial velocity of the object attached to the spring. Defaults

* to zero, which represents an unmoving object. Negative values

* represent the object moving away from the spring attachment point,

* positive values represent the object moving towards the spring

* attachment point. */

这三个属性会影响到属性的变化值。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,120评论 19 139
  • 在iOS实际开发中常用的动画无非是以下四种:UIView动画,核心动画,帧动画,自定义转场动画。 1.UIView...
    请叫我周小帅阅读 8,409评论 1 23
  • =========================================================...
    lavor阅读 8,872评论 0 5
  • (我不知道是不是很多妈妈和我一样,总是很容易被自己的孩子感动,总是觉得自己的孩子就是特别好的......) 这篇日...
    沐璎阅读 4,459评论 0 1
  • 4月21日,一早从泸沽湖颠簸了4个多小时回到丽江古城,吃了黑山羊锅,味道很赞,整个人就复活了。 因为不太喜欢丽江的...
    刘芷睿阅读 2,761评论 3 1

友情链接更多精彩内容