2011-05-12 18 views
2

喜 我有這個識別器,用2觸摸設置,但它只返回一個,不是兩個CGPointlocationOfTouch和numberOfTouches

-(void)gestureLoad { 

UIGestureRecognizer *recognizer; 

recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(numTap2:)]; 
[(UITapGestureRecognizer *)recognizer setNumberOfTouchesRequired:2]; 
[self.view addGestureRecognizer:recognizer]; 
self.tapRecognizer = (UITapGestureRecognizer *)recognizer; 
recognizer.delegate = self; 
[recognizer release]; 

} 

- (void)numTap2:(UITapGestureRecognizer *)recognizer { 

CGPoint location = [recognizer locationInView:self.view]; 
NSLog(@"x %f y %f",location.x, location.y); 

} 

按照我的理解,我循環觸摸的這兩種方法的數量,但我還沒有想出如何:

-(CGPoint)locationOfTouch:(NSUInteger)touchIndex inView:(UIView *)view { 

} 

-(NSUInteger)numberOfTouches { 

} 

非常感謝!

回答

2

在numTap2,使用方法:

CGPoint location = [recognizer locationOfTouch:touchIndex inView:self.view]; 

其中touchIndex是0或1

+0

感謝,但我在哪裏有插入此? – Vins 2011-05-12 14:30:52

+0

好的完美,我開始理解,而不是你放入 - (CGPoint)locationOfTouch:(NSUInteger)touchIndex inView:(UIView *)view? – Vins 2011-05-12 14:47:03

+0

只是刪除這兩條消息 - 你不需要它們 – 2011-05-12 18:16:07