質問

hi i am observing something weird in iOS custom views, where i have a button in side a custom view, i am looking for documentation or your answer to explain why i have this observation

i have a custom view (subclass of UIView), it contains a simple button, i bind the button touch event via addTarget:Action with UITouchUpInside, i just bind it selector to a simple method that NSLog a message

if you display the custom view and hits the button, you can see the message in the console, everything works as expected.

However, if you add a UIGestureReognizer to the custom view, and run it, when you click the button, it no longer prints the message, WHY??? i did more in depth investigation, and by looking at the hittest method IN THE CUSTOM VIEW (the view contains the button) (i override it, but i didn't do anything, i just call super again), the hittest is returning the correct view, i.e. when i click on the button, hittest method of the custom view is returning UIButton

i do not understand the event chain here, can someone pointing the documentation that explains this?

it seems to me when you add the regonizer to the container view of the button, for some reason, the button DOES NOT KNOW how to handle the event, so it asks its superview (custom view in thsi case) to handle it, but why?? i already bind the event handeler to the button via UITouchUPInside

please please help i want to understand this

役に立ちましたか?

解決

Set your recognizer's cancelsTouchesInView property to NO.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top