【发布时间】:2017-07-25 23:22:14
【问题描述】:
在我的应用程序中,我添加了一个 UIButton,但不是让 UIButton 的标准触摸事件变暗然后在触摸事件结束时变为标准颜色,而是添加一个动画,当您单击 UIButton 按钮时变小,然后当触摸事件结束时,UIButton 在触摸事件结束时恢复到常规大小。到目前为止,我已经输入了这段代码,但它似乎不起作用。请告诉我如何完成这个动画。
// whatsTheGame is the UIButton I have
@IBAction func whatsTheGame(_ sender: UIButton) {
logo.isHighlighted = false
UIView.animate(withDuration: 0.3) {
if let centerLogo = self.logo {
centerLogo.transform = CGAffineTransform(scaleX: 0.7, y: 0.7)
}
}
}
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
UIView.animate(withDuration: 0.3) {
if let centerLogo = self.logo {
centerLogo.transform = CGAffineTransform(scaleX: 1, y: 1)
}
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
UIView.animate(withDuration: 0.3) {
if let centerLogo = self.logo {
centerLogo.transform = CGAffineTransform(scaleX: 1, y: 1)
}
}
}
【问题讨论】: