1

I added below codes on ViewController

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    print("started")
}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
    print("ended")
}

but it doesn't print any messages at all.

김동현
  • 91
  • 3
  • 14
  • Try putting these on a view instead of a view controller. (I was surprised to see these can be overridden on a UIViewController.) –  Jan 28 '17 at 12:43
  • @dfd I am a beginner of Swift. could you let me know how to put these codes on View, not ViewController. – 김동현 Jan 29 '17 at 08:08

1 Answers1

3

UIResponder class is an abstract interface for responding to and handling events Apple API Reference

UIWindow, UIViewController, UIView are subclass of UIResponder

if you want to use touchesBegan and touchesEnded, override it

touch event follow responder chain refer apple docs

enter image description here

some touch event occur and your ViewController's view become next responder and hittest successfully touchesBegan called when touch began and touchesEnded called touch ended

Cruz
  • 2,602
  • 19
  • 29