Iphone – Passing a touch event to all subviews of a View Controller

argument-passingiphonesubview

I have a view controller which creates multiple subviews on top of it. All subviews and the view controller accept touches. How can i communicate the touch point information to all the subviews on the screen? Keep in mind that each subview covers the entire screen so after a few additions its a bit like pages in a book. That is, any subviews below the top subview can't be touched directly by the user. I have tried using [self.nextResponder touchesBegan:touches withEvent:event] however this only sends the touch information from the top subview to the superview bypassing all other subviews on the screen. Thanks

Best Answer

I would put another subview ontop of everything. This would grab all the touches that you were interested in and pass them back to the view controller. Your view controller would then iterate through all it's child UIViews, giving them the events.

i.e. something like

for (UIView *view in subviews)
  [view touchesBegan:touches withEvent:event];

though that's assuming that all the subviews you want to pass events to are children of your view controller.