(iPhone)如何处理UITextView上的触摸? [英] (iPhone) How to handle touches on a UITextView?
问题描述
我正在尝试处理iPhone的UITextView上的触摸。我成功设法通过创建UIImageViews的子类来处理点击和其他触摸事件,并实现touchesBegan方法...但是这显然不适用于UITextView :(
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 :(
UITextView启用了用户交互和多点触控,只是为了确保......没有没有欢乐。有人设法处理这个吗?
The UITextView has user interaction and multi touch enabled, just to be sure...no no joy. Anyone managed to handle this?
推荐答案
UITextView(UIScrollView的子类)包含很多事件处理。它处理复制和粘贴以及数据检测器。也就是说,它可能是一个错误,它不会传递未处理的事件。
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.
有一个简单的解决方案:你可以在你自己的版本中继承UITextView并强制你自己的touchesEnded(和其他事件处理消息),你应该调用 [super touchesBegan:touches withEvent:event];
在每个触摸处理方法中。
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");
}
这篇关于(iPhone)如何处理UITextView上的触摸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!