大家好!我需要在同一時間在不同的圖像視圖上檢測2個觸摸。所以我需要在用戶同時觸摸兩個圖像視圖時啓動計時器。觸摸結束時停止定時器。圖像視圖正在屏幕上移動。當我使用一個圖像視圖時沒有問題。你有什麼想法嗎?同時檢測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];
}
感謝所有幫助))
「兩次同時觸摸」 - 同一時間延遲一秒鐘?大約100ms呢?大概1分鐘? –