【问题标题】:UIWebView Subclass with Custom HitTest带有自定义 HitTest 的 UIWebView 子类
【发布时间】:2011-07-25 17:36:33
【问题描述】:

我在 UITableView 中的许多 UITableViewCell 对象中有一个 UIWebView。当您尝试滚动 UITableView 时,有时触摸会“卡住”在 UIWebView 对象上。但是,我仍然需要能够单击 UIWebView 对象中的链接。所以,我创建了一个子类:

#import "SecretWebView.h"


@implementation SecretWebView

-(UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    if ([[event allTouches] count] == 0) {
        return self.superview;
    } else {
        return self; //I have tried many things here...
    }
}

@end

我希望当没有点击链接时我可以返回超级视图(即 TableViewCell),然后返回通常会返回的任何内容,这样我仍然可以点击链接并获得相同的预期行为.除了 UIWebView 允许点击链接的“else”子句之外,一切正常。

在代码中,您会看到我在哪里评论“我在这里尝试了很多事情......”,其中包括以下内容:

return [super hitTest:point withEvent:event];
return self;
return origObj; //where origObj was created in first line from the [super ...] call.

请帮帮我!如何让它忽略除单击链接之外的任何操作!?

【问题讨论】:

  • 另外,如果我只返回超级 hitTest:withEvent: 消息,UIWebView 中的链接工作正常!我不明白dddddd呃。

标签: ios uitableview uiwebview


【解决方案1】:

一般来说,-[UIView hitTest:withEvent:] 会递归地查看它的子视图,并可能返回它自己或它的任何子视图。 在您的情况下,UIWebview 的命中很可能由其子视图之一而不是其本身来处理。通过调用 [super hitTest:withEvent:],您将获得正确的子视图返回。

请参阅this question 了解 hitTest:withEvent: 的工作原理。

【讨论】:

    猜你喜欢
    • 2011-05-11
    • 1970-01-01
    • 1970-01-01
    • 2011-03-10
    • 1970-01-01
    • 1970-01-01
    • 2021-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多