简体   繁体   English

如何快速在辅助功能中使用点击手势?

[英]How to use tap gesture in Accessibility in swift?

I'm working on app for blind people first i needed to use swipe gesture and after search i can do it by using我首先为盲人开发应用程序,我需要使用滑动手势,搜索后我可以使用

 override func accessibilityScroll( direction:       
 UIAccessibilityScrollDirection)-> Bool {
 if direction == UIAccessibilityScrollDirection.Left
 {
   Do what you want to do 
   }
 }

Now I need to use tap gesture and I can't find any function to use make custom tap in Accessibility can anyone help me pleasee!现在我需要使用点击手势,但我找不到任何功能可以在辅助功能中使用自定义点击任何人都可以帮助我吗? Thanks谢谢

You shouldn't use tap gesture for UIAccessibility ot try to add tap gestures to UIAccessibility.您不应该为UIAccessibility使用点击手势,也不要尝试将点击手势添加到 UIAccessibility。 UIAccessibility is meant for the UIElements where the people can see/hear what is on the screen. UIAccessibility适用于人们可以看到/听到屏幕上的内容的UIElements You cannot add UIAccessiility for tap gesture functions.您不能为点击手势功能添加 UIAccessiility。 What you can do is to post a accessibility notification to the user saying tap to perform something.您可以做的是向用户发布可访问性通知,说点击执行某些操作。 Again, you need to use buttons to perform an action in UIAccessibility .同样,您需要使用按钮在UIAccessibility执行操作。

You can override accessibilityScroll method:您可以覆盖accessibilityScroll方法:

override func accessibilityScroll(_ direction: 
    UIAccessibilityScrollDirection) -> Bool {

    super.accessibilityScroll(direction)

    if direction == UIAccessibilityScrollDirection.left {
    // do your stuff            
    }

    if direction == UIAccessibilityScrollDirection.right {
    // do your stuff        
    }
    return true
}

Add this to your code 将此添加到您的代码

overrride func viewDidLoad()
{
super.viewDiDLoad()
let tap = UITapGestureRecognizer(target: self, action: "performTap")
self.view.addGestureRecognizer(tap)
}

And to perform the necessary action, add your required code here 并执行必要的操作,请在此处添加所需的代码

func performTap()
{
   // Perform you action here
}

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

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