Disable entire UIMenuController edit menu in WKWebView
Based on your workaround, I found out that:
-(void)menuWillShow:(NSNotification *)notification{ NSLog(@"MENU WILL SHOW"); dispatch_async(dispatch_get_main_queue(), ^{ [[UIMenuController sharedMenuController] setMenuVisible:NO animated:NO]; });}
Will prevent the menu from flashing 90% of the times.. Still not good enough, but it's another workaround before we find a decent solution.
Try making your view controller become first responder and stop it from resigning first responder
- (BOOL)canResignFirstResponder { return NO;}- (BOOL)canBecomeFirstResponder { return YES;}
https://github.com/dwieringa/WKWebViewEditMenuHidingTest/pull/1
I Fixed it after some observation.
In -canPerformAction:withSender:
I am returning NO
for _share
and _define
options as I don't need them in my project. It works as expected on selection of word for first time, but shows up the options from second time.
Simple fix: Add [self becomeFirstResponder];
in tapGuesture
or Touch delegate methods
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender { SEL defineSEL = NSSelectorFromString(@"_define:"); if(action == defineSEL){ return NO; } SEL shareSEL = NSSelectorFromString(@"_share:"); if(action == shareSEL){ return NO; } return YES;}// Tap gesture delegate method- (void)singleTap:(UITapGestureRecognizer *)sender { lastTouchPoint = [sender locationInView:self.webView]; [self becomeFirstResponder]; //added this line to fix the issue//}