- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"touchesBegan");
//test
UITouch *touch = [event alltouches] anyObject];
if ([touch tapCount] == 2) {
NSLog (@"tapcount 2");
[self.textview becomeFirstResponder];
}
else if ([touch tapCount] == 1) {
NSLog (@"tapcount 1");
[self.textview becomeFirstResponder];
[self.view performSelector:@selector(select:)];
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesBegan:touches withEvent:event];
NSLog(@"touchesMoved");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"****touchesEnded");
[self.nextResponder touchesEnded: touches withEvent:event];
NSLog(@"****touchesEnded");
[super touchesEnded:touches withEvent:event];
NSLog(@"****touchesEnded");
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesCancelled:touches withEvent:event];
NSLog(@"touchesCancelled");
}
我的问题:
我想在UITextView上点击一次即可模拟两个水龙头,这是该代码中的textview.但是当我在textview上点击一次或两次时,我只能从一个和两个水龙头得到NSLog,只有在外面.我应该怎么做才能使它工作?
解决方法
可能我会在这里使用两个
gesture recognizers.
//...some stuff above here probably in you're controllers viewDidLoad UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapRecognized:)]; singleTap.numberOfTapsrequired = 1; [someTextView addGestureRecognizer:singleTap]; [singleTap release]; UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapRecognized:)]; doubleTap.numberOfTapsrequired = 2; [someTextView addGestureRecognizer:doubleTap]; [doubleTap release];
选择器就像:
- (void)singleTapRecognized:(UIGestureRecognizer *)gestureRecognizer {
NSLog(@"single tap");
// ...etc
}
- (void)doubleTapRecognized:(UIGestureRecognizer *)gestureRecognizer {
NSLog(@"double tap");
// ...etc
}