Iphone UITextView触摸事件未触发

Iphone UITextView触摸事件未触发,iphone,iphone-sdk-3.0,uitextview,Iphone,Iphone Sdk 3.0,Uitextview,我有一个UITextView,我想为它检测一次点击 看起来只要覆盖touchesend:withEvent并检查[[toucheanyobject]tapCount]==1,我就可以了,但是这个事件甚至不会触发 如果我覆盖以下4个事件: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; NSLog(@"touchesBega

我有一个
UITextView
,我想为它检测一次点击

看起来只要覆盖
touchesend:withEvent
并检查
[[toucheanyobject]tapCount]==1
,我就可以了,但是这个事件甚至不会触发

如果我覆盖以下4个事件:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    NSLog(@"touchesBegan (tapCount:%d)", touch.tapCount);
    [super touchesBegan:touches withEvent:event];
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        NSLog(@"touches moved");
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    NSLog(@"touchesEnded (tapCount:%d)", touch.tapCount);
        [super touchesEnded:touches withEvent:event];
}

-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
        NSLog(@"touches cancelled");
}
> touchesBegan (tapCount:1)
> touchesCancelled 
> touchesBegan (tapCount:1) 
> touches moved 
> touches moved
> touches moved 
> touchesCancelled
我得到如下输出:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    NSLog(@"touchesBegan (tapCount:%d)", touch.tapCount);
    [super touchesBegan:touches withEvent:event];
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        NSLog(@"touches moved");
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    NSLog(@"touchesEnded (tapCount:%d)", touch.tapCount);
        [super touchesEnded:touches withEvent:event];
}

-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
        NSLog(@"touches cancelled");
}
> touchesBegan (tapCount:1)
> touchesCancelled 
> touchesBegan (tapCount:1) 
> touches moved 
> touches moved
> touches moved 
> touchesCancelled
似乎我从未得到过
touchesend
事件


有什么想法吗?

您可以通过覆盖
canperformation:withSender:
方法来关闭剪切/复制/粘贴,这样您就可以对所有不允许的操作返回NO


希望这能阻止你的触摸被吃掉。

更新:我在这里使用了这项技术:

我不确定这是否是一个bug,但UITextView确实需要利用touch事件来执行3.0版的复制和粘贴弹出菜单,因此这可能解释了为什么它会吞并这个事件

如果你问我的话,那真是太差劲了


更新:我在这里写了一篇博客:

我像这样对UITextview进行了子类化,即使在IOS 5.0.1上,它似乎也能工作。关键是覆盖touchesbeated,而不仅仅是touchesend(这是我真正感兴趣的)


如果调用super,会发生什么情况?我对UITextView子类做了类似的操作,以检测单点击和双点击——它在2.x设备上工作得很好,但在3.0上却不行。@Reed我希望您的文本视图不会滚动。我猜新的复制/粘贴功能会干扰touchesEnded事件。我想知道是否可以将其关闭?我尝试重写此方法并遇到崩溃。我为@selector(select:)和@selector(selectAll:)返回了NO,但它仍然允许选择。好的,修复了崩溃(我忘记将其余的传递给super)无论如何,它似乎没有效果。我仍然可以复制文本。文档说明,此方法也将在响应者链的更上层调用,因此您可能还需要在包含视图中覆盖它…您的博客链接已更改: