UITapGestureRecognizer不会将其状态更改为.Began
,但UILongPressGestureRecognizer会执行此操作.如果由于某种原因,字体想要直接覆盖触摸回调,你可以使用UILongPressGestureRecognizer,其非常短minimumPressDuration
,如0.1,以达到效果.
例如@ Daij-Djan:
class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. var tap = UILongPressGestureRecognizer(target: self, action: Selector("pressedMe:")) tap.minimumPressDuration = 0 self.view.addGestureRecognizer(tap) self.view.userInteractionEnabled = true } func pressedMe(gesture: UITapGestureRecognizer) { if gesture.state == .Began{ self.view.backgroundColor = UIColor.blackColor() } else if gesture.state == .Ended { self.view.backgroundColor = UIColor.whiteColor() } } }