Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(iPhone) How to handle touches on a UITextView?

Tags:

I'm trying to handle touches on a iPhone's UITextView. I successfully managed to handle taps and other touch events by creating a subclass of UIImageViews for example and implementing the touchesBegan method...however that doesn't work with the UITextView apparently :(

The UITextView has user interaction and multi touch enabled, just to be sure...no no joy. Anyone managed to handle this?

like image 384
devguy Avatar asked Mar 05 '09 20:03

devguy


1 Answers

UITextView (subclass of UIScrollView) includes a lot of event processing. It handles copy and paste and data detectors. That said, it is probably a bug that it does not pass unhandled events on.

There is a simple solution: you can subclass UITextView and impement your own touchesEnded (and other event handling messages) in your own versions, you should call[super touchesBegan:touches withEvent:event]; inside every touch handling method.

#import "MyTextView.h"  //MyTextView:UITextView @implementation MyTextView  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{     NSLog(@"touchesBegan"); }  - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{         [super touchesBegan:touches withEvent:event];     NSLog(@"touchesMoved"); }  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{     NSLog(@"****touchesEnded");     [self.nextResponder touchesEnded: touches withEvent:event];      NSLog(@"****touchesEnded");     [super touchesEnded:touches withEvent:event];     NSLog(@"****touchesEnded"); }  - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ [super touches... etc];  NSLog(@"touchesCancelled"); } 
like image 155
2 revs, 2 users 71%Ignacio Enriquez Avatar answered Oct 22 '22 13:10

2 revs, 2 users 71%Ignacio Enriquez