简体   繁体   English

UIwebView加载动画图像无法响应UITapGestureRecognizer

[英]UIwebView load animation image not respond to UITapGestureRecognizer

I use UIWebView as a subView of UIView to load animation image(GIF) from server. 我使用UIWebView作为UIView的子视图来从服务器加载动画图像(GIF)。

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:picLink]]];

And I add Tap gesture to my UIView , but the webView disable this gesture( UIWebView frame = UIView Frame and [view sendSubViewToBack:webView] . 然后将Tap手势添加到我的UIView ,但是webView禁用了此手势( UIWebView frame = UIView Frame[view sendSubViewToBack:webView]

How to solve it? 怎么解决呢? Is there another method to display GIF image. 还有另一种显示GIF图像的方法。 Thanks! 谢谢!

You can put a sibling UIView on top of the UIWebView and add the tap gesture recognizer to that sibling. 您可以将同级UIView放在UIWebView之上,并将轻击手势识别器添加到该同级中。 The code might look like this: 代码可能看起来像这样:

- (void)viewDidLoad {
    [super viewDidLoad];

    UIView *containerView = [[UIView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:containerView];

    UIWebView *webView = [[UIWebView alloc] initWithFrame:containerView.bounds];
    [containerView addSubview:webView];
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://i.imgur.com/eezCO.gif"]]];

    UIView *frontView = [[UIView alloc] initWithFrame:containerView.bounds];
    [containerView addSubview:frontView];
    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
    [frontView addGestureRecognizer:tapRecognizer];
}

- (void)tapped:(UITapGestureRecognizer *)tapRecognizer {
    NSLog(@"tapped");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM