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

前端 未结 2 1819
别跟我提以往
别跟我提以往 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

提交回复
热议问题