【发布时间】:2011-07-05 18:13:24
【问题描述】:
我在 UIScrollView 中有多个自定义 UIWebView 作为子视图。我已经在 UIViewController 中为 UIWebView 实现了触摸方法,但是这些方法没有被调用。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { }
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { }
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { }
我在其他地方读到过,它说 UIScrollView 将使用这些事件。这是有道理的,但是 UIWebView 是否应该在 UIScrollView 本身之前不接收触摸事件?可能发生的情况是 UIWebBrowserView(UIWebView 的子视图)正在使用这些事件。然而,这个类不能被子类化,所以我不能将事件沿着 superview 链发送到 UIScrollView。我在 Apple iOS 文档上阅读过,不应该将 UIWebView 放在 UIScrollView 中,但出于我的目的,我需要这样做。
所以我的问题是:我的自定义 UIWebView(即 UIScrollView 的子视图)如何接收触摸事件?
我的控制器和视图设置如下:
HomeViewController.h /.m /.xib
HomeView.h /.m (is a UIScrollView)
DashboardViewController.h /.m /.xib (custom UIWebView's)
HomeViewController 从包含自定义视图的 Nib 文件加载:HomeView。 DashboardViewController 从 Nib 文件加载。它包含一些标签、滑块等(请注意,这里没有自定义视图 - 我这里没有继承 UIView)。
HomeViewController 动态加载多个 DashboardViewController 并将其视图添加到 HomeView。
DashboardViewController *dashboardViewController = [[DashboardViewController alloc] initWithNibName:@"DashboardViewController" bundle:[NSBundle mainBundle];
[homeView addSubview:dashboardViewController.view];
【问题讨论】:
标签: objective-c ios cocoa-touch uiview uiscrollview