ios4触摸响应事件
我向应用程序添加了一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你说你把它添加为子视图,但我希望你的意思是你用
- (void)pushViewController:(UIViewController *)viewControllerAnimated:(BOOL)animated
推送它你的视图控制器可以响应事件,因为它是一个 UIResponder。 UIView 以及大多数视觉控件(如 UIButton、UISlider 等)也继承自 UIResponder - 但它们基于用户交互实现特定操作。
如果您确实想拦截 UIViewController 中的事件,您将需要处理 TouchBegan/Moved/Ended 事件。如果视图控制器正在显示您想要单击的内容,则更有可能您在视图控制器中至少有一个 UIWebView 或 UIImageView 。
如果 UIWebView 您需要一个 UIWebViewDelegate 实现,
它将让您知道正在打开哪些链接。
如果是 UIImageView,您还需要在看到任何触摸事件之前设置属性
userInteractionEnabled
。如果您正在处理 iAd 的 AdBannerView 类,它也继承自 UIView,因此 UIImageView 的注释适用。然而,ADBannerViewDelegate 是内置交互支持的要求 - 就像 UIWebViewDelegate 一样,您必须实现权限/通知功能,
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
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,