本文介绍了locationOfTouch 和 numberOfTouches的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨我有这个识别器,设置了 2 个触摸,但它只返回一个,而不是两个 CGPoint
hiI have this recognizer, set with 2 touch, but it returns only one, not two CGPoint
-(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);
}
据我所知,我用这两种方法循环触摸次数,但我还没有想出如何:
as I understand, I cycle the number of touch with these two methods, but I have not figured out how to:
-(CGPoint)locationOfTouch:(NSUInteger)touchIndex inView:(UIView *)view {
}
-(NSUInteger)numberOfTouches {
}
非常感谢!
推荐答案
在 numTap2 中,使用:
In numTap2, use:
CGPoint location = [recognizer locationOfTouch:touchIndex inView:self.view];
其中 touchIndex
是 0 或 1.
where touchIndex
is either 0 or 1.
这篇关于locationOfTouch 和 numberOfTouches的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!