How can a superview interecept a touch sequence before any of its subviews?

前端 未结 2 1818
别跟我提以往
别跟我提以往 2021-01-15 14:41

I have a view hierarchy that is layed out as follows:

parentView

 scrollView

    contentViewA

    containerView

         contentViewB

         co         


        
相关标签:
2条回答
  • 2021-01-15 15:17

    Another way of doing this is to add another subview to your ui so it looks like so :

    parentView
      scrollView
        contentViewA
          containerView
            contentViewB
            contentViewC
      touchGrabber
    

    and, in touchGrabber, detect all the touches that you want (by subclassing UIView)

    This is more complicated than Phil Nash's solution but has the advantage that you can add/remove other views from your parentView without having to deal with their userInteractionEnabled value - this is useful if you have a third party library adding views for example.

    However, if you definately only going to have the scrollView, Phil Nash's answer is the way forward!

    Thanks,

    Sam

    0 讨论(0)
  • 2021-01-15 15:22

    To stop the scroll view from intercepting the touch events, set the userInteractionEnabled property like so:

    scrollView.userInteractionEnabled = NO;
    0 讨论(0)
提交回复
热议问题