一周的出色工作成果!如果要在许多页面上保存鼠标事件和用户输入,所有其他答案都不正确。
1)Swizzle方法(由rentzsch / jrswizzle库提供):
[NSClassFromString(@"UIWebDocumentView") jr_swizzleMethod:@selector(canPerformAction:withSender:) withMethod:@selector(myCanPerformAction:withSender:) error:nil];
NSObject + myCanPerformAction.h:
@interface NSObject (myCanPerformAction)
- (BOOL)myCanPerformAction:(SEL)action withSender:(id)sender;
@end
NSObject + myCanPerformAction.m:
#import "NSObject+myCanPerformAction.h"
@implementation NSObject (myCanPerformAction)
- (BOOL)myCanPerformAction:(SEL)action withSender:(id)sender {
if (action == @selector(copy:)) {
return [self myCanPerformAction:action withSender:sender];
}
if (action == @selector(paste:)) {
return [self myCanPerformAction:action withSender:sender];
}
return NO;
}
@end
2)将UIWebView放在UIView上并添加代码:
UITapGestureRecognizer* singleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)] autorelease];
singleTap.numberOfTapsRequired = 2;
singleTap.numberOfTouchesRequired = 1;
singleTap.delegate = self;
[self.view addGestureRecognizer:singleTap];
还有这个:
- (void)handleSingleTap:(UIGestureRecognizer*)gestureRecognizer {
return;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
if ([otherGestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
UITapGestureRecognizer *gesture = (UITapGestureRecognizer *)otherGestureRecognizer;
if (gesture.numberOfTapsRequired == 2) {
[otherGestureRecognizer.view removeGestureRecognizer:otherGestureRecognizer];
}
}
return YES;
}
UIWebView
使用类别扩展。