本文介绍了如何拦截长按UITextView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我试图拦截当用户长按UITextView(放大镜然后出现使用插入符定位器),然后释放触摸,即通常在放大镜之后出现选择和全选选项。



这是否可以?

解决方案

您可以尝试这样:



禁用内置的长按识别器


$ b {
if([recognizer isKindOfClass:[UILongPressGestureRecognizer class]]){
recognizer.enabled = NO(UIGestureRecognizer类型的识别器); $

  ; 
}
}

然后添加您自己的

  UILongPressGestureRecognizer * myLongPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:< your target> action:@selector(< your custom handler>)]; 
[textView addGestureRecognizer:myLongPressRecognizer];
[myLongPressRecognizer release];


Total Objective-C / Cocoa Touch noob here, beware.

I'm trying to intercept when a user long presses on a UITextView (a magnifying glass then appears with the caret positioner) and then releases the touch, i.e. when normally the "Select" and "Select All" Options appear, after the magnifying glass. I want to replace this with my own custom action that is then performed.

Is this possible?

解决方案

You can try something like this:

Disable the built-in long press recognizer

for (UIGestureRecognizer *recognizer in textView.gestureRecognizers) {
  if ([recognizer isKindOfClass:[UILongPressGestureRecognizer class]]){
    recognizer.enabled = NO;
  }
}

Then add your own

UILongPressGestureRecognizer *myLongPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:<your target> action:@selector(<your custom handler>)];
[textView addGestureRecognizer:myLongPressRecognizer];
[myLongPressRecognizer release];

这篇关于如何拦截长按UITextView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-28 18:46