在UITextView中删除UIMenuController

时间:2013-10-29 09:55:04

标签: ios uiwebview uitextview uigesturerecognizer uimenucontroller

我有UIWebView用于显示文章HTML页面。我使用UILongGesture来显示UIMenuController。在UIMenuItem中有一个注释字段。如果单击note,它将显示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];
}

2 个答案:

答案 0 :(得分:0)

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

 tap.enabled = NO;

答案 1 :(得分:0)

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

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


}