我正在开发一个注入触摸的企业应用程序。我使用的方法与KIF框架中的方法相同(参见https://github.com/square/KIF/tree/master/Additions)。
至少有一种情况,此方法不起作用:
当用户点击设备时,注入不再适用于滚动视图。当我注入移动触摸事件时,它们不再滚动。当用户自己在设备上滚动时,注射再次起作用。看起来状态没有使用KIFs方法设置,但是当发生真正的触摸时它由iOS设置。
有人知道更多吗?也许有一个想法,它可能是一个想法?我已经尝试了几个听起来正确的私有API调用,但都没有用。
以下是一些代码,描述了我使用的方法:
触地:
UITouch *touch = [[[UITouch alloc] initAtLocation:point inWindow:hitView.window] autorelease];
[touch setPhase:UITouchPhaseBegan];
UIEvent *newEvent = [hitView _eventWithTouch:touch];
[_activeTouchEvents addObject:touch];
[[UIApplication sharedApplication] sendEvent:newEvent];
触摸移动 UITouch * touch = _activeTouchEvent;
[touch setPhase:UITouchPhaseMoved];
[touch setLocationInWindow:point];
UIEvent *newEvent = [hitView _eventWithTouch:touch];
[[UIApplication sharedApplication] sendEvent:newEvent];
触摸
UITouch* touch = _activeTouchEvent;
[touch setPhase:UITouchPhaseEnded];
[touch setLocationInWindow:point];
UIEvent *newEvent = [hitView _eventWithTouch:touch];
[[UIApplication sharedApplication] sendEvent:newEvent];
[_activeTouchEvent release];
_activeTouchEvent = nil;
UIView(扩展名)
- (UIEvent *)_eventWithTouch:(UITouch *)touch;
{
UIEvent *event = [[UIApplication sharedApplication] performSelector:@selector(_touchesEvent)];
CGPoint location = [touch locationInView:touch.window];
KIFEventProxy *eventProxy = [[KIFEventProxy alloc] init];
eventProxy->x1 = location.x;
eventProxy->y1 = location.y;
eventProxy->x2 = location.x;
eventProxy->y2 = location.y;
eventProxy->x3 = location.x;
eventProxy->y3 = location.y;
eventProxy->sizeX = 1.0;
eventProxy->sizeY = 1.0;
eventProxy->flags = ([touch phase] == UITouchPhaseEnded) ? 0x1010180 : 0x3010180;
eventProxy->type = 3001;
NSSet *allTouches = [event allTouches];
[event _clearTouches];
[allTouches makeObjectsPerformSelector:@selector(autorelease)];
[event _setGSEvent:(struct __GSEvent *)eventProxy];
[event _addTouch:touch forDelayedDelivery:NO];
[eventProxy release];
return event;
}
UITouch(扩展名)
- (id)initAtLocation:(CGPoint)point inWindow:(UIWindow *)window
{
self = [super init];
if (self == nil) {
return nil;
}
// Create a fake tap touch
_tapCount = 1;
_locationInWindow = point;
_previousLocationInWindow = _locationInWindow;
UIView *hitTestView = [window hitTest:_locationInWindow withEvent:nil];
_window = [window retain];
_view = [hitTestView retain];
_gestureView = [hitTestView retain];
_gestureRecognizers = [[NSMutableArray arrayWithArray:[hitTestView gestureRecognizers]] retain];
_phase = UITouchPhaseBegan;
_touchFlags._firstTouchForView = 1;
_touchFlags._isTap = 1;
_timestamp = [[NSProcessInfo processInfo] systemUptime];
return self;
}
- (void)setPhase:(UITouchPhase)phase;
{
_phase = phase;
_timestamp = [[NSProcessInfo processInfo] systemUptime];
}
编辑1:“触及”的代码块不正确