gpt4 book ai didi

ios - [CAKeyframeAnimation setFromValue :]: unrecognized selector sent to instance

转载 作者:行者123 更新时间:2023-11-28 07:22:53 25 4
gpt4 key购买 nike

我正在尝试使用 keyframeanimate 为按钮设置动画,我想修改它的 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

}
}

但是当我运行它时,我遇到了一个异常,如下所示:

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[CAKeyframeAnimation setFromValue:]:无法识别的选择器发送到实例 0x2820e06e0”

最佳答案

我意识到如何解决这个错误。 self.view.layoutIfNeeded() 应该在 block 之外,所以我这样做并修复了错误,所以这里是正确的代码:

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
})

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

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

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

}) { (finishFlag) in

}
}

关于ios - [CAKeyframeAnimation setFromValue :]: unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57542336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com