How to use tap gesture in Accessibility in swift?

风流意气都作罢 提交于 2019-12-20 01:39:27

问题


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


回答1:


You shouldn't use tap gesture for UIAccessibility ot try to add tap gestures to UIAccessibility.UIAccessibility is meant for the UIElements where the people can see/hear what is on the screen. You cannot add UIAccessiility for tap gesture functions. 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.




回答2:


You can override accessibilityScroll method:

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
}



回答3:


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
}


来源:https://stackoverflow.com/questions/36123544/how-to-use-tap-gesture-in-accessibility-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!