简体   繁体   中英

How to pass a touch event to other views?

+-----------------------+  +--------------------+
| A                     |  | A                  |
| +-------------------+ |  | +----------------+ |
| |B                  | |  | | C              | |
| |                   | |  | |                | |
| +-------------------+ |  | +----------------+ |
+-----------------------+  +--------------------+

I have a view hierarchy as above. (Each of B and C takes up whole space of A, Each of them are screen size. B is added first and C is added next)

For a reason, C is getting a touch event for scroll effect
(B is cocos2d-x layer and C(scroll view) sets the B's position when scrollViewDidScroll http://getsetgames.com/2009/08/21/cocos2d-and-uiscrollview/ )

And I want to pass touch event to B or it's subviews when it's not scrolling.

How can I pass the touch event to B here?

So, if I understand your context correctly, B and C do no overlap (at least not entirely) and share the same superview.

The only possibility I see is defining your own custom window, the override

- (void)sendEvent:(UIEvent*)event {

to handle the touches you get in A as you need.

See this thread on SO for an example of changing the destination view of a touch event. You will need to build your own flow to handle the different cases you have to manage and possibly also mess with the touch coordinates by doing some kind of projection.

This same problem is covered in the WWDC 2012 scroll view session .

Steps are..

1. You hide your scrollview.
2. place dummy view where scrollview would be and attach scrollview's panGestureRecognizer to this view.

lo and behold touch goes to the view behind the dummy view when it's not scrolling.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM