1

我有 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];
}
4

2 回答 2

0

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

 tap.enabled = NO;
于 2013-10-29T10:11:24.983 回答
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];


}
于 2013-10-30T06:23:59.347 回答