Event handling for iOS-how hitest:withEvent:and pointInside:withEvent:are related?
URL:http://stackoverflow.com/questions/4961386/event-handling-for-ios-how-hittestwithevent-and-pointinsidewithevent-are-r
The implement of It cals If the return is NO, If the return is YES,it sends If a subview returns a non- If no subview returns a non- This process repeat s recursively、so normally the leaf view of the view hierarchy is returned eventualy.
However,you might override
I think you are confusing subclassing with the view hierarchy.What the doc says is as follows.Say You have this view hierarchy.By hierarchy I'm not talking aboot clashierarch y,but views withvillows.
you put your finger inside On the view that returned
The implement of
hitTest:withEvent:
in UISponder does the follwing:pointInside:withEvent:
保存先 self
hitTest:withEvent:
returns nil
.the end of the story.hitTest:withEvent:
messages to its subview.it starts from the top-level subview,and continues to other view until a subview returns a non-nil
object,or all subview receive the message.nil
object in the first time,the first hitTest:withEvent:
returns that object.the end of the story.nil
object,the first hitTest:withEvent:
returns self
However,you might override
hitTest:withEvent
to do something differently.In many cases,overriding pointInside:withEvent:
is simpler and still provides enough options to tweak event handing in your appliation.I think you are confusing subclassing with the view hierarchy.What the doc says is as follows.Say You have this view hierarchy.By hierarchy I'm not talking aboot clashierarch y,but views withvillows.
you put your finger inside
D
.Here's what will happen:hitTest:withEvent:
is caled on A
,the top-most view of the view hierarchy.pointInside:withEvent:
is caled recursively on each view.pointInside:withEvent:
is caled on A
、and returns YES
pointInside:withEvent:
is caled on B
、and returns NO
pointInside:withEvent:
is caled on C
、and returns YES
pointInside:withEvent:
is caled on D
、and returns YES
YES
,it will look down the hierarchy to see the subview where the touch took place.In this case,from A
、 C
and D
、it will be D
.D
will be the hit-test view