UIView. Why Does A Subviews Outside its Parent's Extent Not Receive Touches?

后端 未结 5 1163
盖世英雄少女心
盖世英雄少女心 2020-12-04 19:29

I have a simple - trivial - UIView parent/child hierarchy. One parent (UIView). One child (UIButton). The parents bounds are smaller then it\'s child\'s bounds so that a por

5条回答
  •  既然无缘
    2020-12-04 20:07

    The problem is the responder chain. When you touch the display it will go down from the parents to the childen.

    So .. when you touch the screen the parent will see that the touch is outside of it's own bounds and so the children will not even asked.

    The function that does that is the hitTest. If you have your own UIView class you can overwrite it and return the button by yourself.

    - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
    

提交回复
热议问题