UIButton not clickable outside initial frame of an UIScrollView

前端 未结 2 1560
北恋
北恋 2021-02-20 16:16

I got stuck with the strange behavior of UIScrollView that I cannot click on the UIButton after I enlarge the contentSize of the UIScrollView.

What I wanted to do:

2条回答
  •  孤城傲影
    2021-02-20 16:54

    I assume that the button is direct or indirect child of the contents view you load from the xib file.

    The problem is because you changed the scroll view's contentSize but did not change the frame of the contents view. Superviews participate in touch hit testing. You can place a subview outside of its superview bounds and by default the subview will not be clipped but touch events will not be delivered to it because the superview checks during hit testing that the touch is outside of its bounds and rejects the touch. See UIView hitTest:withEvent: for details.

提交回复
热议问题