I want to show SFSymbols animation on button click. I use this code to do this:
var copyButton: UIButton = {
let button = UIButton()
button.setImage(UIImage(systemName: "doc.on.doc.fill", withConfiguration: UIImage.SymbolConfiguration(scale: .large))!.withTintColor(.black.withAlphaComponent(0.2), renderingMode: .alwaysOriginal), for: .normal)
button.translatesAutoresizingMaskIntoConstraints = false
button.backgroundColor = .black.withAlphaComponent(0.1)
button.imageView?.contentMode = .scaleAspectFit
button.addTarget(self, action: #selector(copyButtonAction), for: .touchUpInside)
return button
}()
@objc func copyButtonAction(sender: UIButton) {
copyButton.imageView?.addSymbolEffect(.bounce.down, options: .nonRepeating, animated: true)
}
Is the best and right way to do this? Every time when I click on my button I Adding Symbol Effect. Should I add it once? Or Should I do it every time? Should I remove it after button click? Or do something?