UITextView触摸事件未触发 [英] UITextView touch events not firing

查看:135
本文介绍了UITextView触摸事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UITextView ,我想检测一下。

I have a UITextView that I want to detect a single tap for.

看起来我会只需覆盖 touchesEnded:withEvent 并检查 [[touches anyObject] tapCount] == 1 即可甚至没有开火。

It looks like I would be fine with simply overriding touchesEnded:withEvent and checking [[touches anyObject] tapCount] == 1 , however this event doesn't even fire.

如果我覆盖这样的4个事件:

If I override the 4 events like this:

-(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

似乎我从来没有得到 touchesEnded 事件。

It seems I never get the touchesEnded event.

任何想法?

推荐答案

更新:我最终使用了技术在这里:
https://devforums.apple.com/message/94569#94569

Update: I ended up using the technique here: https://devforums.apple.com/message/94569#94569

我不确定这是不是一个错误,但是UITextView确实需要利用触摸事件来执行复制和放大的弹出菜单;粘贴3.0,这可以解释为什么它会吞下这个事件。

I'm not sure if this is a bug or not, but the UITextView does need to utilize the touch events to do the popup menu for copy & paste for 3.0, so that might explain why it swallows this event.

如果你问我,那就太蹩脚了。

Pretty lame if you ask me.

更新:我在这里写了博客: http:// benscheirman .com / 2009/07 / detect-on-a-uitextview

Update: I blogged about this here: http://benscheirman.com/2009/07/detecting-a-tap-on-a-uitextview

这篇关于UITextView触摸事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆