// 画面に指が触れた時
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
// 次のViewにタッチイベントを渡す時
next?.touchesBegan(touches, with: event)
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
next?.touchesMoved(touches, with: event)
}
// 画面から指が離れた時
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
next?.touchesEnded(touches, with: event)
}
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
next?.touchesCancelled(touches, with: event)
}
★ タッチした場所にあるViewをタグにより識別する
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touchEvent = touches.first!
print(touchEvent.locationInView(self.view))
let tag = touchEvent.view!.tag
switch tag {
case 999:
print("tapped")
default:
break
}
}