你说你将它添加为子视图,但我希望你的意思是你用它推送它
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
您的视图控制器可以响应事件,因为它是一个 UIResponder。 UIView 以及 UIButton、UISlider 等大多数可视控件也继承自 UIResponder - 但它们根据用户交互实现特定操作。
如果你真的想拦截 UIViewController 中的事件,你需要处理 touchesBegan/Moved/Ended 事件。如果视图控制器显示您想要单击的内容,则更有可能您在视图控制器中至少有一个 UIWebView 或 UIImageView 。
如果 UIWebView 你需要一个 UIWebViewDelegate 实现
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
将让您知道正在打开哪些链接。
如果是 UIImageView,您还需要在看到任何触摸事件之前设置属性 userInteractionEnabled。
如果您正在处理 iAd 的 AdBannerView 类,该类也继承自 UIView,因此适用于 UIImageView 的 cmets。但是 ADBannerViewDelegate 是内置交互支持的要求 - 就像 UIWebViewDelegate 一样,您必须实现权限/通知功能,
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave