Context: In the iOS UIKit project, written in swift
lets say I have a Super view - 'A' with frame (0, 0, 320, 200)
and I have a subview say 'B' with frame (0, 0, 320, 600)
and the view 'B' is added as a subview to the view 'A'
now the subview 'B' is having a table view with in it
Issue facing
tablew view with in my subview B is responsive only till its super view position i.e. its scrollable and didSelectRowAt is invoked only within the frame (0, 0, 320, 200) which its super view frame
when I tap on any row beyond that frame, is not responding, could somebody please help me how do I fix this wired issue, thanks in advance.
Probably the best way to handle this is by overriding a
hitTestmethod to return rather your target view. Something like this:This
OverridingHitTestViewwill send events to whatever you setforwardToview. In your case it should be the table view which is your sub view.Your
OverridingHitTestViewmust be placed below your table view and it needs to be large enough to include all of the area you wish to handle.I created a trivial example all-in-code just to test run it.
To dig a bit more into the hit test:
The idea is that we check what would the view originally report. And if it would report
selfwe forward the call to our target view. The reason for it is thatselfwill be returned in cases where user did actually press within this view. And also that it did not press some subview on this view. This allows that other elements such as buttons still work correctly within this view (not all events are forwarded to the target view).I hope this sets you on the right path if not solve your issue. You could still use the same method but change conditions to for instance look for touch locations within a window or whatever really. The point being that you simply need to return a correct view on
hitTest.