简体   繁体   中英

How can I set a UIView to be the only receiver of touches?

My app has a slide out navigation setup where the presented views (left and center) are both child view controllers of a main view controller. Now I am trying to use a magnifying glass within a UIView presented within the view of the child view controller . However both the child view controller and the main view controller have gesture recognizers.

I was hoping that setting exclusiveTouch to true on the desired UIView would do the trick, but it doesn't at all. How can I put my application in a state such that the main view controller and the child view controller both don't receive these touches (I'm thinking of an off/off button) when I want the contained UIView only to receive them? I need something that can be contained within one method rather than upending my entire architecture. Thanks for any suggestions

ps I'm happy to provide code, but it would be a lot of code to show the implementation of the slide out controller, etc. Am happy to post whatever is requested.

Not sure if this would work... But you could try adding a TapGestureRecognizer with a handler that doesn't do anything to the mainViewController.view and childViewController.view when you enter the exclusiveTouch state, then be sure to remove it when you exit the exclusiveTouch state.

I believe that the topmost gesture recognizer on a UIView is the one that routes all gestures on that view, so this should keep the gesture from being picked up and handled by the other recognizers lower on the stack.

Try this and let me know how it works.

The easiest solution was to disable all gesture recognizers and not change anything else. Then UIView did capture the touches.

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