简体   繁体   English

如何对UIAccessibilityElement子类中的“内部触摸”事件做出反应?

[英]How to react to a “touch up inside” event in UIAccessibilityElement subclass?

I have a map with drawn items. 我有一张画有物品的地图。 The map handles touch events and determines the touched items as if they were buttons. 该地图处理触摸事件,并确定触摸的项目就像按钮一样。

I made the map a container and implemented the methods to return accessibleElements. 我将地图设置为容器,并实现了用于返回accessibleElements的方法。 For each item I create one instance of a UIAccessibilityElement subclass. 对于每一项,我创建一个UIAccessibilityElement子类的实例。

It seems UIAccessibilityAction protocol has no callback for a "tap" or "button pressed" event. 似乎UIAccessibilityAction协议没有针对“轻击”或“按下按钮”事件的回调。 How would I mimic the effect of a UIButton with UIAccessibilityElement then? 那我如何用UIAccessibilityElement模仿UIButton的效果?

Assuming you are running under iOS 5 or iOS 6, consider the following workaround. 假设您在iOS 5或iOS 6下运行,请考虑以下解决方法。 It is not optimal, but will work until there is a better way: 它不是最佳方法,但是可以使用,直到有更好的方法为止:

  1. Create a dummy view that is not, itself, an accessibility element. 创建一个本身不是可访问性元素的虚拟视图。
  2. On this view, implement your "tap" handling in -touchesEnded:withEvent: . 在此视图上,在-touchesEnded:withEvent:实现“点击”处理。
  3. Set your accessibility element's accessibilityActivationPoint to a value that falls within this dummy view. 将可访问性元素的accessibilityActivationPoint设置为该虚拟视图内的值。

Your dummy view will receive touch events when the corresponding accessibility element is activated. 当相应的辅助功能被激活时,您的虚拟视图将接收触摸事件。 Make sure to ignore touch handling in your dummy view if VoiceOver and other assistive technologies are not running. 如果VoiceOver和其他辅助技术未运行,请确保在虚拟视图中忽略触摸处理。

EDIT: Another less hacky approach is to implement a tap gesture recognizer on the view you're concerned with, convert the coordinate from -touchesEnded:withEvent: to screen coordinates, and manually hit test the point against the frames of your accessibility elements. 编辑:另一个不那么棘手的方法是在您关注的视图上实现轻击手势识别器,将-touchesEnded:withEvent:的坐标转换为屏幕坐标,然后针对可访问性元素的框架手动命中测试点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM