[CAKeyframeAnimation setFromValue:]:无法识别的选择器已发送到实例

问题描述 投票:1回答:1

[我正在尝试使用keyframe为按钮设置动画,并为要修改的按钮设置tintColor和按钮宽度约束,我想将其缩放2倍,反之亦然,这是我的代码

func InitialAnimationToTutorialButton() {
        UIView.animateKeyframes(withDuration: 1.5, delay: 0, options: [.repeat], animations: {

            UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0.1, animations: {
                self.tutorialButton.tintColor = UIColor(rgb: 0xDB4284)
                self.tutorialButtonWidth.constant = 60
                self.view.layoutIfNeeded()
            })

            UIView.addKeyframe(withRelativeStartTime: 0.1, relativeDuration: 0.1, animations: {
                self.tutorialButton.tintColor = UIColor(rgb: 0x554E6E)
                self.tutorialButtonWidth.constant = 30
                self.view.layoutIfNeeded()
            })

            UIView.addKeyframe(withRelativeStartTime: 0.3, relativeDuration: 0.1, animations: {
                self.tutorialButton.tintColor = UIColor(rgb: 0xDB4284)
                self.tutorialButtonWidth.constant = 60
                self.view.layoutIfNeeded()
            })

            UIView.addKeyframe(withRelativeStartTime: 0.4, relativeDuration: 0.1, animations: {
                self.tutorialButton.tintColor = UIColor(rgb: 0x554E6E)
                self.tutorialButtonWidth.constant = 30
                self.view.layoutIfNeeded()
            })

        }) { (finishFlag) in

        }
    }

但是当我运行它时,我遇到了一个异常,就像下面这样:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CAKeyframeAnimation setFromValue:]: unrecognized selector sent to instance 0x2820e06e0'

ios swift animation keyframe
1个回答
0
投票
我意识到了如何解决这个错误。 self.view.layoutIfNeeded()应该在块之外,所以我做到了,并纠正了错误,所以这里是正确的代码:
© www.soinside.com 2019 - 2024. All rights reserved.