I have UIWebView for displays article HTML pages. I used UILongGesture for displays UIMenuController. In UIMenuItem have a field on notes. If click note it displays the UITextView. But if i longpress in UITextView, the UIMenuItem displaying. How to hide?
- (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];
}
If use click note:
- (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];
}
UIGestureRecognizer has a property named enabled. This should be good enough to disable long press:
tap.enabled = NO;
Got the answer. This code is work for me.
- (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];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.