【发布时间】:2019-04-16 14:32:11
【问题描述】:
我想在点击时更改UIView 的颜色,并在点击事件后将其改回原来的颜色
我已经实现了这两种方法,但它们的行为没有给我所需的结果
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
backgroundColor = UIColor.white
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
backgroundColor = UIColor.gray
}
这两种方法有效,但在按下UIView 2 秒后,它就有效了。此外,它不会在按下后将UIView 的颜色改回白色(简而言之,在我重新启动应用程序之前它会保持灰色)
我在UIView上使用轻击手势
【问题讨论】: