UITapGestureRecognizer Programmatically trigger a tap in my view

前端 未结 8 1084
耶瑟儿~
耶瑟儿~ 2020-12-09 10:05

Edit: Updated to make question more obvious

Edit 2: Made question more accurate to my real-world problem. I\'m actually looking to take a

8条回答
  •  攒了一身酷
    2020-12-09 10:28

    I think you have multiple options here:

    1. May be the simplest would be to send a push event action to your view but i don't think that what you really want since you want to be able to choose where the tap action occurs.

      [yourView sendActionsForControlEvents: UIControlEventTouchUpInside];

    2. You could use UI automation tool that is provided with XCode instruments. This blog explains well how to automate your UI tests with script then.

    3. There is this solution too that explain how to synthesize touch events on the iPhone but make sure you only use those for unit tests. This sounds more like a hack to me and I will consider this solution as the last resort if the two previous points doesn't fulfill your need.

提交回复
热议问题