迅速的颜色变化显示不同的颜色

时间:2018-09-12 05:50:07

标签: swift uiimage tint

我正在尝试在图像视图上执行缩放动画。完成后,我将图像更改为红色版本。但是在这之间它显示了一种奇怪的蓝色,我不想显示。这是我用于动画的代码。谢谢

 self.likeAnimateView.image = self.likeAnimateView.image!.withRenderingMode(UIImageRenderingMode.alwaysTemplate)
                        UIView.animate(withDuration: 0.182,
                        animations: {
                           self.likeAnimateView.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)

                        },
                        completion: { _ in
                            UIView.animate(withDuration: 0.182) {
                                self.likeAnimateView.transform = CGAffineTransform.identity

                                  self.likeAnimateView.image = UIImage(named: "heartsel") // Red image
                            }
                        })

1 个答案:

答案 0 :(得分:0)

根据@Karthikeyan Bose的建议。我在动画之前添加了这一行代码。

self.likeAnimateView.image = UIImage(named: "heart")//Deafault color before the animation to get rid of the blue color

UIView.animate(withDuration: 0.182,
               animations: {
                   self.likeAnimateView.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)

               },
               completion: { _ in
                   UIView.animate(withDuration: 0.182) {
                       self.likeAnimateView.transform = CGAffineTransform.identity

                       self.likeAnimateView.image = UIImage(named: "heartsel") // Red image
                   }
               })