How do you REALLY remove Copy from UIMenuController
The technique you linked to still seems to work. I implemented a UIWebView
subclass with these methods, and only the A and B items appeared.
+ (void)initialize
{
UIMenuItem *itemA = [[UIMenuItem alloc] initWithTitle:@"A" action:@selector(a:)];
UIMenuItem *itemB = [[UIMenuItem alloc] initWithTitle:@"B" action:@selector(b:)];
[[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObjects:itemA, itemB, nil]];
[itemA release];
[itemB release];
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
BOOL can = [super canPerformAction:action withSender:sender];
if (action == @selector(a:) || action == @selector(b:))
{
can = YES;
}
if (action == @selector(copy:))
{
can = NO;
}
NSLog(@"%@ perform action %@ with sender %@.", can ? @"can" : @"cannot", NSStringFromSelector(action), sender);
return can;
}
How to remove Copy option from share within the UIMenuController on IOS9?
Try this out:
#import "MyTextView.h"
@implementation MyTextView
- (BOOL)canPerformAction:(SEL)iAction withSender:(id)iSender {
SEL shareSelector = NSSelectorFromString(@"_share:");
if (iAction == shareSelector) {
return NO;
}
if (iAction == @selector(copy:)) {
return NO;
}
return [super canPerformAction:iAction withSender:iSender];
}
How to remove paste from UIMenuController?
you may subclass a UITextView
or UITextField
, and add these code below.
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
// Show your own menu item only
return (action == @selector(showMyAlert:));
}
How to remove th COPY UIMenuItem in UIMenuController
You're going to have to do some hijacking. I don't even know if it is possible. It looks like it probably responds to a gesture event called UILongPressGestureRecognizer.
You need to find out what view has the gesture added to it. something like this.
NSArray *gestures = myWebView.gestureRecognizers;
for(int i=0;i<[gestures count];i++){
UIGestureRecognizer g = [gestures objectAtIndex:i];
if([g isKindOfClass:UILongPressGestureRecognizer.Class]){
[myWebView removeGestureRecognizer:g];
break;
}
}
but I don't think the gesture is on the UIWebview directly. It is on one of its subviews.
So it might be on this subview
UIScrollView *sview = [[mywebview subviews] objectAtIndex:0];
If not on that one then it is probably on the view that is on top the most, which is what I suspect. It is an undocumented View type, but if you treat it as a UIView for the methods we are calling, it is presumably safe. Also, because you are treating it as a UIView, it isn't against the rules as far as I understand.
UIScrollView *sview = [[mywebview subviews] objectAtIndex:0];
UIView *realWebView = [[sview subviews] objectAtIndex:10];
The reason I didn't write the snippet (which is untested) to try to remove the gesture from all of the views is because it is important you know which view you remove it from.
After you remove it, you need to write your own UILongPressGestureRecognizer and then add the new one to the respective view (the view it was removed from).
You have lost all your functionality of copy select etc... but now you can implement your own.
If you want some of the old functionality, I think I know how you can get it back, but I can't promise this is allowed or safe.
Before you remove the gesture you need to override a method to UIView. You should be able to do it in your current working class file (at the top of the file)
@implementation UIView (extended)
-(BOOL) respondsToSelector:(SEL)aSelector {
printf("SELECTOR: %s\n",
[NSStringFromSelector(aSelector) UTF8String]);
return [super respondsToSelector:aSelector];
}
@end
I can't promise anything, but this should log the name of EVERY method that is called in your view.
Run your app and execute the copy,paste,select,select all methods. Your log should show what methods get called when you press the buttons. It may show several methods when you push a button, you probably just want the first.
Now when you create a menuItem you know what selector to assign to it.
This is all just a guess. Hope it helps.
How to disable Copy & Define UIMenuItems of UIMenuController in UITextfield
Finally solved it by subclassing UITextView
(created custom class for it) and just added
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(copy:))
{
return NO;
}
return NO;
}
inside of .m file of my custom TextView subclass.
After that "Copy" doesn't appear any more, with or without [menu update]
;
Related Topics
Swift/How to Use Dispatch_Group with Multiple Called Web Service
Have a Variable with Multiple Types in Swift
How to Add Older Version of iOS Sdk in Xcode 4.5
My Swift 4 Uiscrollview with Autolayout Constraints Is Not Scrolling
Get the Frame of Uibarbuttonitem in Swift
Disable Bounce Effect in Uipageviewcontroller
Xcode 4.2: How to Import .H File from Subproject
Swiftui: Deleting Last Row in Foreach
How to Observe Changes in Userdefaults
How to Convert Date Like \/Date(1440156888750-0700)\/ to Something That Swift Can Handle
Xcode 8.1 Push Notifications in Swift 2.3 with Firebase Integration Not Getting
iOS 8 Uiactivityviewcontroller and Uialertcontroller Button Text Color Uses Window's Tintcolor
Where and When to Get Data for Watch Complication
"Too Many Symbol Files" After Successfully Submitting My Apps