我希望我的图像在被点击时有动画效果,这是我目前的代码,当我点击图像时,不会因为某种原因而发生任何事情。
lazy var profileImageView: UIImageView = {
let imageView = UIImageView()
imageView.image = UIImage(named: "made")
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.contentMode = .scaleAspectFill
imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(taptap)))
imageView.isUserInteractionEnabled = true
return imageView
}()
@objc func taptap() {
let pulse = CASpringAnimation(keyPath: "transform.scale")
pulse.duration = 0.6
pulse.fromValue = 0.95
pulse.toValue = 1.0
pulse.autoreverses = true
pulse.repeatCount = 2
pulse.initialVelocity = 0.5
pulse.damping = 1.0
layer.add(pulse, forKey: nil)
}发布于 2018-07-16 05:17:53
除了将动画添加到ImageView行之外,一切看起来都很好。替换这一行:
layer.add(pulse, forKey: nil)有:
profileImageView.layer.add(pulse, forKey: nil)您需要将Core Animations添加到视图的layer中,这里是您的profileImageView。
https://stackoverflow.com/questions/51354713
复制相似问题