CAAnimation動畫實際是加在layer上鞠苟,在執(zhí)行完畢之后键菱,動畫效果就會消失蒂秘,若要得到動畫后的效果拆融,需要加上兩個屬性
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;
//動畫執(zhí)行后的狀態(tài)模式
group.fillMode = kCAFillModeForwards;
//動畫執(zhí)行后不刪除該狀態(tài)
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;
//動畫執(zhí)行后不刪除該狀態(tài)
group.removedOnCompletion = NO;
動畫執(zhí)行完畢都會得到我們想要的結(jié)果夯巷,但是設置完CASpringAnimation的這兩個屬性后,動畫執(zhí)行完畢哀墓,layer屬性的變化往往的不到我們想要的結(jié)果
/* The mass of the object attached to the end of the spring. Must be greater
than 0. Defaults to one. */
@property CGFloat mass;// 質(zhì)量
/* The spring stiffness coefficient. Must be greater than 0.
* Defaults to 100. */
@property CGFloat stiffness;//剛度趁餐,剛度是指材料或結(jié)構(gòu)在受力時抵抗彈性變形的能力
/* 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. */
這三個屬性會影響到屬性的變化值。