ios如何使UITextView检测一下?

前端之家收集整理的这篇文章主要介绍了ios如何使UITextView检测一下?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
  2. NSLog(@"touchesBegan");
  3.  
  4. //test
  5. UITouch *touch = [event allTouches] anyObject];
  6. if ([touch tapCount] == 2) {
  7. NSLog (@"tapcount 2");
  8. [self.textview becomeFirstResponder];
  9.  
  10. }
  11.  
  12. else if ([touch tapCount] == 1) {
  13. NSLog (@"tapcount 1");
  14. [self.textview becomeFirstResponder];
  15. [self.view performSelector:@selector(select:)];
  16.  
  17.  
  18. }
  19.  
  20. }
  21.  
  22. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
  23. [super touchesBegan:touches withEvent:event];
  24. NSLog(@"touchesMoved");
  25. }
  26.  
  27. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
  28. NSLog(@"****touchesEnded");
  29. [self.nextResponder touchesEnded: touches withEvent:event];
  30. NSLog(@"****touchesEnded");
  31. [super touchesEnded:touches withEvent:event];
  32. NSLog(@"****touchesEnded");
  33. }
  34.  
  35. - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
  36. [super touchesCancelled:touches withEvent:event];
  37. NSLog(@"touchesCancelled");
  38. }

我的问题:

我想在UITextView上点击一次即可模拟两个水龙头,这是该代码中的textview.但是当我在textview上点击一次或两次时,我只能从一个和两个水龙头得到NSLog,只有在外面.我应该怎么做才能使它工作?

解决方法

可能我会在这里使用两个 gesture recognizers.
  1. //...some stuff above here probably in you're controllers viewDidLoad
  2.  
  3. UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapRecognized:)];
  4. singleTap.numberOfTapsrequired = 1;
  5. [someTextView addGestureRecognizer:singleTap];
  6. [singleTap release];
  7.  
  8. UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapRecognized:)];
  9. doubleTap.numberOfTapsrequired = 2;
  10. [someTextView addGestureRecognizer:doubleTap];
  11. [doubleTap release];

选择器就像:

  1. - (void)singleTapRecognized:(UIGestureRecognizer *)gestureRecognizer {
  2. NSLog(@"single tap");
  3. // ...etc
  4. }
  5.  
  6. - (void)doubleTapRecognized:(UIGestureRecognizer *)gestureRecognizer {
  7. NSLog(@"double tap");
  8. // ...etc
  9. }

猜你在找的iOS相关文章