Pass touches through to underlying UIViews [iOS]

Pass touches through to underlying UIViews [iOS]

Sometimes there is a need to pass touches through to underlying layers. Consider the following app:

ttv_demoSS_1

ttv_demoSS_2

We can accomplish the goal of getting the scroll view to receive the touches from the overlaid legend view in both the collapsed and expanded state using this simple and safe open source library.
NATouchThroughView

Your view hierarchy in the above example might look like this:

.UIView (main view controller view)
….UIScrollview (map)
….UIView (legend view container)
…….UIButton (expand legend button)
…….UIImageView (legend image)

You make changes so that your new view hierarchy looks like this:

.UIView (main view controller view)
….UIScrollview (map)
….UIView (legend view container –> change to NARootTouchThroughView in Interface Builder)
…….UIView* (change to ANTouchThroughView)
…….UIButton (expand legend button)
…….UIImageView (legend image)

*A transparent view placed in the red box region as show above. Change its class to ANTouchThroughView in Interface Builder

Now any touches in the ANTouchThroughView region will get forwarded below NARootTouchThroughView. Therefore the map UIScrollView can be moved around when the user is touching in that region.

See the README and demo project at the github link.

Leave a Reply

Your email address will not be published. Required fields are marked *