WKWebview点击图片查看大图

WKWebview点击看大图
废话不说直接上代码,用运行时解决这个问题

#import 
- (void)setMethod:(NSArray *)imgUrlArray {
    objc_setAssociatedObject(self, &imgUrlArrayKey, imgUrlArray, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (NSArray *)getImgUrlArray {
    return objc_getAssociatedObject(self, &imgUrlArrayKey);
}

- (NSArray *)getImageUrlByJS:(WKWebView *)wkWebView {
    //js方法遍历图片添加点击事件返回图片个数 这个看你咋改
    //document.getElementById(\"content\").getElementsByTagName(\"img\");\
    //document.getElementsByTagName(\"img\");\
    
    
    
    static  NSString * const jsGetImages =
    @"function getImages(){\
    var objs = document.getElementById(\"content\").getElementsByTagName(\"img\");\
    var imgUrlStr='';\
    for(var i=0;i
- (void)showBigImage:(NSURLRequest *)request
                show:(UIViewController *)handleVC{
    NSString *str = request.URL.absoluteString;
    if ([str hasPrefix:@"myweb:imageClick:"]) {
        NSString *imageUrl = [str substringFromIndex:@"myweb:imageClick:".length];
        NSArray *imgUrlArr = [self getImgUrlArray];
        NSInteger index = 0;
        for (NSInteger i = 0; i < [imgUrlArr count]; i++) {
            if([imageUrl isEqualToString:imgUrlArr[i]]){
                index = i;
                break;
            }
        }
//这个是图片的数组  [self getImgUrlArray]
    }
}

你可能感兴趣的:(WKWebview点击图片查看大图)