단일 터치 및 드래그를 이미 처리하는 UIView를 서브 클래 싱했습니다. 이 뷰의 상호 작용을 향상시켜 드래그하는 동안 두 번째 손가락 (보기의 다른 위치)으로 사용자가 터치하면 시스템이 메시지를 인쇄합니다. 내가 선언 한 내 헤더 파일에서복잡한 iOS 멀티 터치 상호 작용 - 어떤 제안?
:
NSString *key; // This unique key identifies the first touch
내하는 .m 파일 내가 가진 :
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *t in touches) {
if (key == NULL)
{
key = [[[NSValue valueWithPointer:t] description] copy];
}
if ([key isEqualToString:[[NSValue valueWithPointer:t] description]])
{
NSLog(@"calling parent to handle single touch");
[super touchesBegan:[NSSet setWithObject:t] withEvent:event];
}
else
{
[self twoTouchDetected];
}
}
}
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *t in touches) {
if ([key isEqualToString:[[NSValue valueWithPointer:t] description]])
{
[super touchesMoved:[NSSet setWithObject:t] withEvent:event];
}
}
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *t in touches) {
if ([key isEqualToString:[[NSValue valueWithPointer:t] description]])
{
[super touchesEnded:[NSSet setWithObject:t] withEvent:event];
key = NULL;
}
}
}
불행하게도이 문제가 나는 코드에 찌르기를했습니다 이행. 처음으로 (한 손가락으로 드래그하는 동안) 두 번째 그림과 접촉하면 시스템에서 즉시 등록합니다. 그러나 두 번째 손가락으로 두 번째로 터치하면 (첫 번째 손가락으로 끌기를 계속하면서) 두 번째 손가락 터치는 첫 손가락을들 때까지 등록되지 않습니다. 두 번째 손가락의 이벤트가 백업됩니다.
때로는 두 번째 손가락이 아닌 첫 번째 손가락이 아닌 터치 데이터로 부모가 호출되는 경우가 있습니다.
[GestureRecognizers] (http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html)를 사용하지 않는 이유는 무엇입니까? – beryllium
두 손가락을 사용하여 시도했는데 하나는 GestureRecognizer를 탭하지만 손가락으로 드래그하면 작동하지 않습니다. 인식기는 touchesBegin 메소드에 전달되기 전에 모든 이벤트를 처리합니다. – Joe
드래그 용으로 UIPanGestureRecognizer – beryllium