我想知道如何在一个UIView上传递一个tap到一个UITextView。这是我到目前为止的代码:
- (void)foundTap:(UITapGestureRecognizer *)recognizer {
label.text = @"Touch detected";
[self.view bringSubviewToFront:aTextView];
[aTextView touchesBegan:touches withEvent:event];
}
现在,这显然不能工作,因为触摸和事件没有定义。但是我怎么定义它们呢?我不能声明触摸为1(不会工作)。我可以这样初始化它:
UITouch *touches =[touches anyObject];
但是,触摸仍然是未声明的。我也不知道该怎么宣布这个事件。如果你使用- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {}
方法,这通常很容易,但是我想传递tap而不是触摸。如有任何帮助,我将不胜感激。
编辑:
我重写了这个方法,但是我仍然不能把tap传递给UITextView。我现在需要双击来编辑它,即第一次点击将aTextView带到前面,第二次点击将编辑UITextView(因为它在前面,因此接收所有触摸滑动等):
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesMoved:touches withEvent:event];
UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self.view];
CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x); // will always be positive
CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y); // will always be positive
if (deltaY == 0 && deltaX == 0) {
label.text = @"Touch"; [self performSelector:@selector(eraseText) withObject:nil afterDelay:2];
[self.view bringSubviewToFront:aTextView];
[self.view bringSubviewToFront:doneEdit];
[aTextView touchesBegan:touches withEvent:event];
}
}
看看前面的SO问题iPhone: detection Tap in MKMapView是否对你有所帮助。