How to “transfer” first responder from one UIView to another?

前端 未结 2 1757
遥遥无期
遥遥无期 2021-01-06 22:06

I have a UIView subclass (CustomView for purposes of this question) that has its own handling of all touches events (Began, Moved, Ended, Cancelled

相关标签:
2条回答
  • 2021-01-06 22:39

    you have to override canBecomeFirstResponder to return YES otherwise becomeFirstResponder does nothing. This is already done on UIControls, but not on UIViews

    0 讨论(0)
  • 2021-01-06 22:47

    Just use hitTest:withEvent: to figure out what view "should" be receiving the event, then forward on the event to the appropriate view. You might have to do a little bit of dancing around to intercept events before they go to the button, but this is what hitTest:withEvent: was made for.

    0 讨论(0)
提交回复
热议问题