每个人!我需要同时检测不同图像视图上的 2 次触摸。因此,当用户同时触摸两个图像视图时,我需要启动计时器。并在触摸结束时停止计时器。图像视图在屏幕上移动。当我使用一个图像视图时没有问题。你有什么想法吗?
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *allTouches = [event allTouches];
for (UITouch *touch in allTouches)
for (UITouch *touch2 in allTouches)
{
CGPoint location = [touch locationInView:touch.view];
CGPoint location2 = [touch2 locationInView:touch2.view];
if ([touchArea2.layer.presentationLayer hitTest:location2]) {
touchArea2.image = [UIImage imageNamed:@"TouchAreaTouched"];
}
if ([touchArea.layer.presentationLayer hitTest:location]) {
touchArea.image = [UIImage imageNamed:@"TouchAreaTouched"];
timerTouch = 10;
touchTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(randomVoid) userInfo:nil repeats:YES];
} else if (![touchArea.layer.presentationLayer hitTest:location]){
[touchTimer invalidate];
touchTimer = nil;
} }
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *allTouches = [event allTouches];
for (UITouch *touch in allTouches)
for (UITouch *touch2 in allTouches) {
CGPoint location = [touch locationInView:touch.view];
CGPoint location2 = [touch2 locationInView:touch2.view];
if (![touchArea.layer.presentationLayer hitTest:location]){
touchArea2.image = [UIImage imageNamed:@"TouchArea"];
touchArea.image = [UIImage imageNamed:@"TouchArea"];
[touchTimer invalidate];
touchTimer = nil;
}
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
touchArea.image = [UIImage imageNamed:@"TouchArea"];
[touchTimer invalidate];
}
谢谢你的帮助))