【问题标题】:remove UIMenuController in UITextView删除 UITextView 中的 UIMenuController
【发布时间】:2013-10-29 09:55:04
【问题描述】:

我有 UIWebView 用于显示文章 HTML 页面。我使用 UILongGesture 来显示 UIMenuController。在 UIMenuItem 中有一个关于注释的字段。如果单击注意它会显示 UITextView。但是如果我在 UITextView 中长按,UIMenuItem 会显示。如何隐藏?

- (void)viewDidLoad
{
 NSMutableArray *items = [[[UIMenuController sharedMenuController] menuItems] mutableCopy];
    if (!items) items = [[NSMutableArray alloc] init];

    UIMenuItem *menuItem;
    menuItem = [[UIMenuItem alloc] initWithTitle:@"BookMark" action:@selector(book:)];
    [items addObject:menuItem];
    [menuItem release];
    menuItem = [[UIMenuItem alloc] initWithTitle:@"Notes" action:@selector(note:)];
    [items addObject:menuItem];
    [menuItem release];

    [[UIMenuController sharedMenuController] setMenuItems:items];


    [items release];



    UILongPressGestureRecognizer *tap = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(tapTest:)];
    [tap setDelegate:self];
    [wbCont.scrollView addGestureRecognizer:tap];

    wbCont.userInteractionEnabled=YES;
[self.view addSubview:wbCont];


}

如果使用点击注释:

- (void)note:(id)sender   {

    NSLog(@"Note");

   // wbCont.userInteractionEnabled=NO;


    if ([UIMenuController sharedMenuController]) {

        [UIMenuController sharedMenuController].menuVisible = NO;

    }

    txtview = [[UITextView alloc]initWithFrame:CGRectMake(0,0,320,568)];

    txtview.font = [UIFont fontWithName:@"Helvetica" size:12];
    txtview.font = [UIFont boldSystemFontOfSize:12];
    txtview.backgroundColor = [UIColor whiteColor];
    txtview.scrollEnabled = YES;
    txtview.pagingEnabled = YES;
    txtview.editable = YES;
     txtview.tag = mainTag*10000;



    [self.view addSubview:txtview];
}

【问题讨论】:

    标签: ios uiwebview uitextview uigesturerecognizer uimenucontroller


    【解决方案1】:

    UIGestureRecognizer 有一个名为 enabled 的属性。这应该足以禁用长按:

     tap.enabled = NO;
    

    【讨论】:

    • 我需要设置这个inside note方法吗?
    【解决方案2】:

    得到了答案。这段代码对我有用。

    - (BOOL) canPerformAction:(SEL)action withSender:(id)sender
    {
    
        if (wbCont.superview != nil && ![txtview isFirstResponder]) {
    
     if (action == @selector(copy:))
     {
    
     return NO;
    
    
    }
        if (action == @selector(book:))
        {
            return YES;
        }
        else if (action == @selector(note:))
        {
            return YES;
        }
    
        }else if(txtview.subviews != nil){
    
    
    
            if (action == @selector(copy:))
            {
    
                return NO;
    
    
            }
            if (action == @selector(book:))
            {
                return NO;
            }
            else if (action == @selector(note:))
            {
                return NO;
            }
    
    
        }
    
        return [super canPerformAction:action withSender:sender];
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-03
      • 1970-01-01
      • 2018-12-23
      • 1970-01-01
      相关资源
      最近更新 更多