简体   繁体   中英

iOS: send a signal from a UIView on touch events?

I am writing an iPad app for work, and this app uses a custom UIView (so I can't change its code). I've been having issues intercepting touch events and passing them on to this app, so figure that I could send a signal from the view to my view controller when a touch happens.

The problem though, is that with a UIControl, I can send a signal, but I don't think I can do the same from a UIView. Is there a way to do this?

You can use a UITapGestureRecognizer and that will call a method which you can then call a delegate method in your UIViewController or send a notification using NSNotificationCentre which your ViewController listens for. Here is the documentation for working with a UITapGestureRecognizer https://developer.apple.com/library/ios/documentation/uikit/reference/UITapGestureRecognizer_Class/Reference/Reference.html

But if you need any help understanding the examples let me know.

Using UITouch looks a close one to me.

UITouch *touch = [[event allTouches] anyObject];
CGPoint touchPoint = [touch locationInView:self.view];

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