如何以编程方式触发 UIView 的点击手势识别器 [英] How to trigger tap gesture recognizer of UIView programmatically

查看:50
本文介绍了如何以编程方式触发 UIView 的点击手势识别器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将点击 gesture 识别器附加到 UIView 并以编程方式触发它.我成功找到了一种方法来查找 UIView 的点击手势识别器.但现在我不知道如何以编程方式触发它.我正在开发应用 crawler.因此,如果我有一个 ViewController 的源代码,那么我的爬虫将开始爬行查找 ViewController 的所有 subviews.此外,爬虫会发现 gesture 附加到 subviews.并触发点击gesture.

I want to get tap gesture recogniser attached to an UIView and trigger it programatically. I successfully found a way to find tap gesture recogniser of an UIView. But now I don't know how to trigger it programatically. I am working on app crawler. So if I have a source code of a ViewController then, my crawler will start crawling find all the subviews of ViewController. Also the crawler will find gesture attached to the subviews. And trigger tap gesture.

注意:我知道如何将手势识别器附加到 UIView 并触发它.但就我而言,我想自动化应用程序的点击过程.考虑一下我想在运行时找到 UIView 的点击手势识别器并触发它.

Note : I know how to attach gesture recogniser to UIView and trigger it. But in my case I wanted to automate the clicking process of an app. Just consider as I want to runtime find tap gesture recogniser of UIView and trigger it.

推荐答案

我通过创建假触摸解决了这个问题.由于手势不公开其动作和选择器,因此无法触发手势.但是因为我有 UIView 想要点击.我可以在那个 UIView 上创建一个假触摸.这种假触摸会自动触发点击手势.链接对此非常有帮助.

I solved this by creating fake touches. Triggering gesture was not possible as gestures does not expose its action and selector. But as I have UIView on which I want to tap. I can create a fake touch on that UIView. This fake touch will automatically trigger the tap gesture. This link was very helpful for this.

这篇关于如何以编程方式触发 UIView 的点击手势识别器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆