简体   繁体   English

隐藏UIMenuController显示“粘贴”,“选择”,“全选”

[英]hide UIMenuController displays“ paste”,“select”,“selectAll”

I am developing an app that supports IM. 我正在开发一个支持IM的应用程序。 Below is a UITextField , up is a UITableView displaying historial messages in bubbles( UIView ). 下面是一个UITextField ,一个是UITableView ,它以气泡形式显示历史消息( UIView )。 Bubble has add longPressGesture , UIMenuController is called by the longPressGesture. Bubble添加了UIMenuControllerUIMenuControllerUIMenuController调用。 My problem is when the textField is firstResponder ,the keyboad is showing, then UIMenuController is called by longPressGesture, normally it works fine. 我的问题是,当textField是firstResponder时 ,显示了键盘,然后UIMenuController调用了UIMenuController ,通常它可以正常工作。 But if there is text in the textField,the menuController show more items than I expected,like "select","selectAll". 但是,如果textField中有文本,则menuController将显示比我预期更多的项目,例如“ select”,“ selectAll”。

Here belows is my code: 下面是我的代码:

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    if (action == @selector(copyMenuAction:)||
        action == @selector(deleteMenuAction:)||
        action == @selector(resendMenuAction:)||
        action == @selector(forwardMenuAction:))
    {
        return YES;
    }
   //    else if (action == @selector(cut:)||
   //             action == @selector(copy:)||
   //             action == @selector(paste:))
   //    {
   //        return NO;
   //    }
    else
        return [super canPerformAction:action withSender:sender];

    return  NO;
   }

  -(BOOL) canBecomeFirstResponder{
    return YES;
   }

Try to add gesture recogniser only in UITableView . 尝试仅在UITableView添加手势识别器。

UILongPressGestureRecognizer *longGes = [[UILongPressGestureRecognizer alloc] 
  initWithTarget:self action:@selector(handleLongPress:)];
longGes.minimumPressDuration = 2.0; //seconds
longGes.delegate = self;
[self.tableView addGestureRecognizer: longGes];

Then in the gesture handler: 然后在手势处理程序中:

-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
    CGPoint p = [gestureRecognizer locationInView:self.tableView];

    NSIndexPath *indexPath = [self.myTableView indexPathForRowAtPoint:p];
    if (indexPath == nil) {
        NSLog(@"long press on table view but not on a row");
    }
    else { 
        if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
            NSLog(@"long press on table view at row %d", indexPath.row);
        }
        else {
            NSLog(@"gestureRecognizer.state = %d", gestureRecognizer.state);
        }
    }
}

Hope this helps.. :) 希望这可以帮助.. :)

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

相关问题 在显示附加到inputAccessoryView的UIMenuController中隐藏'select','selectAll','paste'? - Hiding 'select', 'selectAll', 'paste' in a UIMenuController displayed attached to a inputAccessoryView? 捕获复制/粘贴事件UIMenuController - catch the copy/ paste event UIMenuController 如何使用UIMenuController iOS5.1防止UITextView上的复制/粘贴/选择弹出框 - How do Prevent a copy/paste/select popover on a UITextView using UIMenuController iOS5.1 UIMenuController不隐藏系统项目 - UIMenuController do not hide system items 从UiMenucontroller隐藏复制选项 - Hide copy option from UiMenucontroller iOS在UITableView中创建像popover(UIMenuController)的“复制粘贴” - iOS create “copy paste” like popover (UIMenuController) in UITableView 如何在KIF框架中选择UIMenuController的UIMenuItem? - how to select UIMenuItem of UIMenuController in KIF framework? selectall uitextfield并不总是选择全部 - selectall uitextfield does not always select all 以其他语言显示select selectAll复制剪切… - display the select selectAll copy cut … in other language 在 React Native webview IOS/Android 上隐藏复制/共享/全选菜单 - Hide copy/share/selectAll menu on react native webview IOS/Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM