UITapGestureRecognizer Programmatically trigger a tap in my view

前端 未结 8 1068
耶瑟儿~
耶瑟儿~ 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:38
    CGPoint tapPoint = [gesture locationInView:self.view];
    

    should be

    CGPoint tapPoint = [gesture locationInView:gesture.view];
    

    because the cgpoint should be retrieved from exactly where the gesture target is rather than trying to guess where in the view it's in

    0 讨论(0)
  • 2020-12-09 10:40

    There is a much simpler way to trigger a touch for a UITapGestureRecognizer in a unit test using a single line. Assuming you have a var that holds a reference to the tap gesture recognizer all you need is the following:

    singleTapGestureRecognizer?.state = .ended
    
    0 讨论(0)
提交回复
热议问题