0

Despite the accepted answer, I'm still hoping for a more detailed one, with examples.

I got many views and I just want to, wherever the user is, gather the touch input on the screen.

How can we, despite the warnings, detect the touch from any class without worrying about other views?

edit: I've tried using touchesBegan on the front most view (which is working fine) and [super touchesBegan ...] or [self.nextResponder ...] but that didn't trigger it from the main class.

I also tried using UIImage from the back view with no success. Lastly I though of using some alert, but I'm not sure if it's possible to tweak it as to make it invisible, so I decided asking first what's the best way.

Specially good if it's iOS3 compatible.

Community
  • 1
  • 1
cregox
  • 17,674
  • 15
  • 85
  • 116

1 Answers1

3

Are you trying to support an old iPhone OS version and thus stuck with -touchesBegan, -touchesMoved, etc?

If not, I suggest you use UIGestureRecognizers instead. You wont have to worry about other views that way. The view that gets the touch will get it's gesture recognizer executed, no need to worry about hit testing.

Altealice
  • 3,572
  • 3
  • 21
  • 41
  • 1
    For older versions of iOS you could use a custom `UIWindow` class for your app and override `-sendEvent:` to implement your own gesture recognition before sending events on to the normal event delivery mechanisms. – Jonah Jan 14 '11 at 21:07
  • Altealice, nothing special, just a newbie. I didn't know about `UIGestures` nor where to look for "interfacing with touch". But when googling for "*xcode iphone touch*" I ended up on those results from few different sources. Gona try that new stuff now! Would you have any code to show? – cregox Jan 14 '11 at 21:30
  • Actually, I rather stick with old iOS indeed. I didn't know `UIGestures` is iOS4 only. @Jonah, your hint sounds lovely. I'll try it. Again, any example you can provide would help a lot! :) - you probably meant something like this: http://stackoverflow.com/questions/273450/iphone-detecting-user-inactivity-idle-time-since-last-screen-touch/309535#309535 – cregox Jan 14 '11 at 22:01
  • I blogged an example of how I did this on an old iOS 3.x app here: http://blog.carbonfive.com/2009/07/13/iphone-gesture-recognition/ – Jonah Jan 15 '11 at 01:23
  • Yeah, it's why I've noted that maybe you're trying to use an old iOS (when it was still named iPhone OS, hehe). UIGestures were added in iOS 3.2. But if you're targetting newer devices, I suggest using them, as they will eliminate a lot of hard work. :) – Altealice Jan 15 '11 at 03:11