[NSConcreteValue doubleValue]: unrecognized selector sent to instance

今天需求说要给在进入某个页面给某个按钮加上放大效果,心想这还不简单,于是三下五除二的把动画加上提交测试了.

下面是动画的代码

    NSTimeInterval time = CACurrentMediaTime();
    time = time + 0.5;
    
    CAKeyframeAnimation *animation = [CAKeyframeAnimation  animationWithKeyPath:@"transform.scale"];
    
    //设置value
    CATransform3D scale1 = CATransform3DMakeScale(1.1, 1.1, 1);
    CATransform3D scale2 = CATransform3DMakeScale(1.0, 1.0, 1);
    animation.values = @[[NSValue valueWithCATransform3D:scale2],[NSValue valueWithCATransform3D:scale1],[NSValue valueWithCATransform3D:scale2]];
    
    //重复次数 默认为1
    animation.repeatCount = 1;
    //设置是否原路返回默认为NO
    animation.autoreverses = NO;
    animation.beginTime = time;
    animation.duration = 0.5;
    animation.keyTimes = @[@0.0,@0.7,@1];
    
    animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    //给这个view加上动画效果
    [view.layer addAnimation:animation forKey:@"transform.scale"];

 

然而后面却出现了一个诡异的bug.当动画正在进行的时候滚动scrollView,则会崩溃,并且报下面的错误.

[NSConcreteValue doubleValue]: unrecognized selector sent to instance

上stackoverflow上发现解释如下,

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.

翻译一下就是transform.scale应该用double类型的数值来赋值,如果用NSValue封装好的值来给fromValue和toValue赋值的话,则会解析不到对应的值,表现为app崩溃.

于是修改代码如下,完美运行,不会崩溃了.

    NSTimeInterval time = CACurrentMediaTime();
    time = time + 0.5;
    
    //设置value
    CAKeyframeAnimation *animation = [CAKeyframeAnimation  animationWithKeyPath:@"transform.scale"];
    
    //设置value
    animation.values = @[@1,@1.1,@1];
    
    //重复次数 默认为1
    animation.repeatCount = 1;
    //设置是否原路返回默认为NO
    animation.autoreverses = NO;
    animation.beginTime = time;
    animation.duration = 0.5;
    animation.keyTimes = @[@0.0,@0.7,@1];
    
    animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    //给这个view加上动画效果
    [view.layer addAnimation:animation forKey:@"transform.scale"];

 

转载于:https://www.cnblogs.com/Caersi/p/9671228.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值