swift - tvos:UIViewController 没有收到 touchesBegan

标签 swift tvos touchesbegan first-responder

我正在尝试为 Apple tv4 (tvos) 编写一个应用程序。当我的应用启动时,view controller 会收到 touchesBegan 事件,因为它应该如此。

不涉及太多细节,应用程序创建、移动和删除 subview 以响应用户的交互。

一段时间后, View Controller 不再接收到 touchesBegan(这是我正在尝试调试的奇怪错误)。

由于我认为问题与响应者链有关,所以我做了以下两个实验:

  1. 如果我让 View Controller 覆盖并从 canBecomeFirstResponder 返回 true,那么问题仍然会发生,但发生的频率要低得多
  2. 如果我不覆盖该函数而是检查谁是第一响应者,那么我会发现该应用程序没有第一响应者,甚至在奇怪的错误发生之前也是如此。也就是说,即使App正常运行,也没有第一响应者!

问题什么可以阻止 touchesBegan 被调用?它与响应者更改有关吗?如果是,请解释上面的 2。

最佳答案

您应该如何“触摸”在非触摸屏电视上呈现的 View ?

你不是.. tvOS 不像 iOS 那样无法检测到触摸,因为 Apple TV 不支持支持触摸屏的输入设备。

相反,您使用 UIFocusEngine 来处理与 View 层次结构中呈现的内容的交互。

从 Apple 的开发者库中查看“Controlling the User Interface with the Apple TV Remote”以获取更多信息。

关于swift - tvos:UIViewController 没有收到 touchesBegan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34381183/

相关文章:

xcode - 无法为支持 VAST 模板的 Apple TV tvOS 找到任何视频播放器

ios - touchesBegan 被 AppDelegate 而不是 UIView 的子类捕获

uitableview - iOS 7 : Dragging in UITableView/delaysContentTouches seems not working

ios - SKSpriteNode 不稳定滑动?

ios - 导航到下一个和上一个 subview (就像菜单)

ios - Swift 错误 fatal error : unexpectedly found nil while unwrapping an Optional value

swift - 试图了解与通用枚举相关的 "Cannot convert value of type ... to expected argument type"错误

ios - 重新加载 View 时,Xcode Swift IOS Eureka LabelRow 不更新标题

ios - 有没有办法查询 VoiceOver 转子模式?

swift - 根据 tvOS 深色模式或浅色模式更改图像?