How to disable popup menu items like Select, Selec

2019-02-27 19:50发布

How to disable popup menu items like Select, Select All, Suggest..., Define (on UIWebView)?

I have found the following information on the help but don't understand how to use it:

For the editing menu commands, this is the shared UIApplication object. Depending on the context, you can query the sender for information to help you determine whether a command should be enabled.

1条回答
Explosion°爆炸
2楼-- · 2019-02-27 20:38

Swizzle the following method:

#import "NSObject+myCanPerformAction.h"

@implementation NSObject (myCanPerformAction)

- (BOOL)myCanPerformAction:(SEL)action withSender:(id)sender {
    if (action == @selector(copy:)) {
        return [self myCanPerformAction:action withSender:sender]; // not a recursion
    }
    if (action == @selector(paste:)) {
        return [self myCanPerformAction:action withSender:sender]; // not a recursion
    }
    return NO;
}

@end

Swizzling:

[[UIWebDocumentView class] jr_swizzleMethod:@selector(canPerformAction:withSender:) withMethod:@selector(myCanPerformAction:withSender:) error:nil];
查看更多
登录 后发表回答