gpt4 book ai didi

swift - 为什么动画会改变图像的颜色?

转载 作者:行者123 更新时间:2023-11-28 05:37:35 26 4
gpt4 key购买 nike

我有 func,它可以改变图像并产生一些效果:

  private func changeStarIcon(from: String, to: String) {
UIView.animateKeyframes(withDuration: 0.5, delay: 0.0, options: UIView.KeyframeAnimationOptions.calculationModeCubic, animations: {
UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 0.2, animations: {
(self.navigationItem.rightBarButtonItems?[0].customView as? UIButton)?.imageView?.transform = CGAffineTransform(scaleX: 1.1, y: 1.1)
})
UIView.addKeyframe(withRelativeStartTime: 0.2, relativeDuration: 0.2, animations: {
(self.navigationItem.rightBarButtonItems?[0].customView as? UIButton)?.imageView?.transform = CGAffineTransform.identity
let fadeAnim = CABasicAnimation(keyPath: "contents")
fadeAnim.fromValue = UIImage(named: from)
fadeAnim.toValue = UIImage(named: to)
fadeAnim.duration = 0.3
(self.navigationItem.rightBarButtonItems?[0].customView as? UIButton)?.imageView?.layer.add(fadeAnim, forKey: "contents")
(self.navigationItem.rightBarButtonItems?[0].customView as? UIButton)?.setImage( UIImage(named: to)?.withRenderingMode(.alwaysOriginal), for: .normal)
})
}) { success in
(self.navigationItem.rightBarButtonItems?[0].customView as? UIButton)?.setImage( UIImage(named: to)?.withRenderingMode(.alwaysOriginal), for: .normal)
}
}

当我使用这个函数时,在动画中间我的图像变成灰色(但图像原本是白色的)。我不明白为什么会这样。

enter image description here

最佳答案

为您尝试这个按钮:

button.adjustsImageWhenHighlighted = false

关于swift - 为什么动画会改变图像的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58132226/

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