【发布时间】:2019-08-10 20:00:57
【问题描述】:
所以我有一个UIButton Extension,它允许我的应用程序中的所有按钮都有一个很好的微妙动画。但是最近我想给几个按钮一个特殊的动画,但我不确定如何给这几个按钮一个特定的不同动画,而不是我为所有UIButtons 普遍设置的动画。有没有办法override这个动画只需几个特定的按钮?
按钮动画通用扩展代码:
extension UIButton {
override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
{
self.transform = CGAffineTransform(scaleX: 0.6, y: 0.6)
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 6, options: .allowUserInteraction, animations: {
self.transform = CGAffineTransform.identity
}, completion: nil)
super.touchesBegan(touches, with: event)
}
}
【问题讨论】:
标签: ios swift uibutton core-animation swift-extensions