我会根据您的情况调整我的另一个答案。
canPerformAction:实际上是在内部调用的,UIWebDocumentView而UIWebView不是通常不能子类化的 。借助一些运行时魔法,这是可能的。
我们创建一个具有一个方法的类:
@interface _SwizzleHelper : UIView @end
@implementation _SwizzleHelper
-(BOOL)canPerformAction:(SEL)action
{
    //Your logic here
    return NO;
}
@end
一旦你有了一个想要控制其动作的 web 视图,你就可以迭代它的滚动视图的子视图并学习这个UIWebDocumentView类。然后,我们动态地将上面创建的类的超类设置为子视图的类(UIWebDocumentView - 但我们不能提前说,因为这是私有 API),并将子视图的类替换为我们的类。
#import "objc/runtime.h"    
-(void)__subclassDocumentView
{
    UIView* subview;
    for (UIView* view in self.scrollView.subviews) {
        if([[view.class description] hasPrefix:@"UIWeb"])
            subview = view;
    }
    if(subview == nil) return; //Should not stop here
    NSString* name = [NSString stringWithFormat:@"%@_SwizzleHelper", subview.class.superclass];
    Class newClass = NSClassFromString(name);
    if(newClass == nil)
    {
        newClass = objc_allocateClassPair(subview.class, [name cStringUsingEncoding:NSASCIIStringEncoding], 0);
        if(!newClass) return;
        Method method = class_getInstanceMethod([_SwizzleHelper class], @selector(canPerformAction:));
        class_addMethod(newClass, @selector(canPerformAction:), method_getImplementation(method), method_getTypeEncoding(method));
        objc_registerClassPair(newClass);
    }
    object_setClass(subview, newClass);
}