ios4触摸响应事件

发布于 2024-10-13 02:55:27 字数 215 浏览 3 评论 0原文

我向应用程序添加了一个 ViewController 以支持广告横幅。该应用程序基于 UINavigationController,因此我将 ViewController 作为子视图添加到 UINavigationController。现在,在 Safari 中触摸打开广告时,广告横幅区域无法识别。我试图让 ViewController 成为FirstResponder,但这不起作用。有人对如何修复有任何想法吗?

I added a ViewController to an app for ad banner support. The app was based on a UINavigationController so I added the ViewController as a subview to the UINavigationController. Now the area of the ad banner does not recognize when it is touched to open the ad in safari. I have tried to make the ViewController becomeFirstResponder but that doesn't work. Does anyone have any thoughts on how to fix?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞慾 2024-10-20 02:55:27

你说你把它添加为子视图,但我希望你的意思是你用

- (void)pushViewController:(UIViewController *)viewControllerAnimated:(BOOL)animated

推送它你的视图控制器可以响应事件,因为它是一个 UIResponder。 UIView 以及大多数视觉控件(如 UIButton、UISlider 等)也继承自 UIResponder - 但它们基于用户交互实现特定操作。

如果您确实想拦截 UIViewController 中的事件,您将需要处理 TouchBegan/Moved/Ended 事件。如果视图控制器正在显示您想要单击的内容,则更有可能您在视图控制器中至少有一个 UIWebView 或 UIImageView 。

如果 UIWebView 您需要一个 UIWebViewDelegate 实现,

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

它将让您知道正在打开哪些链接。

如果是 UIImageView,您还需要在看到任何触摸事件之前设置属性 userInteractionEnabled

如果您正在处理 iAd 的 AdBannerView 类,它也继承自 UIView,因此 UIImageView 的注释适用。然而,ADBannerViewDelegate 是内置交互支持的要求 - 就像 UIWebViewDelegate 一样,您必须实现权限/通知功能,

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave

you say you added it as a subview, but I hope you mean you pushed it with

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated

Your view controller can respond to events because it is a UIResponder. UIView and therefore most visual controls like UIButton, UISlider etc. inherit from UIResponder also - but they implement specific actions based on user interaction.

If you really want to intercept events in a UIViewController you will need to handle touchesBegan/Moved/Ended events. More likely you have at least a UIWebView or UIImageView in the view controller if it is displaying something you want to click on.

If UIWebView you'll need a UIWebViewDelegate implementing

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

will let you know what links are being opened.

If a UIImageView you will also need to set the property userInteractionEnabled before you see any touch events.

If you're dealing with iAd's AdBannerView class, that inherits from UIView also, so comments for UIImageView apply. HOWEVER ADBannerViewDelegate is a requirement for built-in interaction support - just like UIWebViewDelegate, you must implement a permission/notification function,

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文