Passing a touch event to all subviews of a View Controller

本秂侑毒 提交于 2019-12-03 16:35:46

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.

Imlement your touch method only in the superview. From there iterate over all subviews and send them the touch method.

Alternatively you can send NSNotification to all the subviews. And in the subvews class you can have a better control and can handle the notifications to perform some task.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!