It's all in the cards 一切尽在卡牌之中。
前言
最近APP里面的动画比较多,天天沉浸在动画的世界不能自拔,让app“动”起来的感觉倍爽。今天就突然遇到之前没有到遇到,如题目。
造成崩溃部分的代码
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
NSValue *value0 = [NSValue valueWithCGAffineTransform:CGAffineTransformMakeScale(0, 0)];
NSValue *value1 = [NSValue valueWithCGAffineTransform:CGAffineTransformMakeScale(0.9, 0.9)];
NSValue *value2 = [NSValue valueWithCGAffineTransform:CGAffineTransformMakeScale(1.1, 1.1)];
NSValue *value3 = [NSValue valueWithCGAffineTransform:CGAffineTransformMakeScale(1, 1)];
anim.values = @[value0, value1, value2, value3];
anim.duration = 0.3;
[self.contentView.layer addAnimation:anim forKey:@"scaleAnimation"];
嗯,代码很简单,一看都懂,一run就崩,一查就知道原因了,人家说:
The transform.scale should be a double type, if you assign fromValue or toValue of CABasicAnimation a
NSValue type, it cann't convert to double value, and so App crashed.
于是乎:
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
anim.values = @[@0, @0.9, @1.1, @1];
anim.duration = 0.3;
[self.contentView.layer addAnimation:anim forKey:@"scaleAnimation"];
后记
菜是原罪!
网友评论