可以模拟水龙头吗?

And*_*rea 8 iphone objective-c

我知道可以截取屏幕上的点击,但我想知道是否可以在屏幕上模拟点击(使用x和y坐标).谢谢

mad*_*ik3 3

UITouch *touch = [[UITouch alloc] initInView:view];
UIEvent *eventDown = [[UIEvent alloc] initWithTouch:touch];

[touch.view touchesBegan:[eventDown allTouches] withEvent:eventDown];

[touch setPhase:UITouchPhaseEnded];
UIEvent *eventUp = [[UIEvent alloc] initWithTouch:touch];

[touch.view touchesEnded:[eventUp allTouches] withEvent:eventUp];

[eventDown release];
[eventUp release];
[touch release];
Run Code Online (Sandbox Code Playgroud)

从这里 http://cocoawithlove.com/2008/10/synthesizing-touch-event-on-iphone.html

  • 否决因为 - 这种技术脱离了上下文,并且需要更多使用私有 API 的代码(在链接中)。 (14认同)
  • 赞成,因为 - 一般而言,合成触摸需要访问某种私有 API。 (5认同)