简体   繁体   English

ios-UITapGestureRecognizer与UITextView

[英]ios - UITapGestureRecognizer with UITextView

I have a scrollable, non-ediable UITextView. 我有一个可滚动的,不可编辑的UITextView。 I want to add a gesture recognizer to it so when double tap it, a tool bar will show, double tap it again, tool bar will hide. 我要向其中添加一个手势识别器,因此当双击它时,将显示一个工具栏,再次双击它,则工具栏将隐藏。

I have disabled the selection function of the text view by subclassing it and override canBecomeFirstResponder to return NO. 我通过子类化禁用了文本视图的选择功能,并覆盖canBecomeFirstResponder以返回NO。

It seems ok when i just simply add the tap recognizer to it. 当我只是向其中添加拍子识别器时,这似乎还可以。

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showOrHideToolbars)];
tapRecognizer.numberOfTapsRequired = 2;
tapRecognizer.numberOfTouchesRequired = 1;
[textView addGestureRecognizer:tapRecognizer];

It works good, excepts if i tap and hold on the text view, after that, the recognizer will not receive any action any more. 效果很好,除非我点击并按住文本视图,此后,识别器将不再接收任何动作。

This means, if I tap and hold on the text view (i guess text view goes into a selection mode even i disable the selection function), no more double tap can be detected now. 这意味着,如果我点击并按住文本视图(即使我禁用了选择功能,我想文本视图也会进入选择模式),现在无法再检测到双击。

I tried to use single tap then problem is gone but i do need to use double tap. 我尝试使用单按,然后问题消失了,但我确实需要使用双按。

I also tried to override touch event handler methods, but no use. 我也尝试重写触摸事件处理程序方法,但没有用。

There are a number of other gesture recognizers attached to a text view. 文本视图上还附加了许多其他手势识别器。 Since you don't seem to need them. 由于您似乎不需要它们。 You can remove them. 您可以删除它们。

textView.gestureRecognizers = nil;

before adding your double tap recognizer. 在添加您的双击识别器之前。 It works. 有用。

Thanks... I managed it via Deepdak's suggestion... The following code will do the required thing :) 谢谢...我是通过Deepdak的建议来管理的...以下代码将完成所需的操作:)

UITapGestureRecognizer *taprecog = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openFolderController)];
taprecog.numberOfTapsRequired = 2;
taprecog.numberOfTouchesRequired = 1;

NSMutableArray *arr = [[NSMutableArray alloc]initWithArray:[textView gestureRecognizers]];
for (int i = 0; i < [arr count]; i++) {
    if ([[arr objectAtIndex:i] isKindOfClass:[UITapGestureRecognizer class] ]) {
        [arr removeObject:[arr objectAtIndex:i]];
    }   
}

[textView addGestureRecognizer:taprecog];
[taprecog release];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM