【问题标题】:How To Add One UIGestureRecognizer to All UITextView without blocking textView touches如何在不阻止 textView 触摸的情况下向所有 UITextView 添加一个 UIGestureRecognizer
【发布时间】:2016-07-20 12:27:52
【问题描述】:

如何在不阻止 textView 触摸的情况下向所有 UITextView 添加一个 UIGestureRecognizer..

我想在任何人触摸任何 UITextView 时调用一个方法。请任何人给我答案。

【问题讨论】:

  • 您的实际问题是什么?

标签: ios objective-c uitextfield uigesturerecognizer uitapgesturerecognizer


【解决方案1】:

<UITextFieldDelegate> - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField

【讨论】:

    【解决方案2】:

    只需使用UITextFieldDelegate 方法或在UITextField 下添加UIView 并将手势识别器 添加到UIView

    【讨论】:

      【解决方案3】:

      首先你必须添加uitextfielddelegate

      <UITextFieldDelegate> 
      

      然后使用那个方法

      (BOOL)textFieldShouldBeginEditing:(UITextField *) textField
      

      【讨论】:

      • 然后兄弟该方法已满。
      【解决方案4】:

      试试这样:

      - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
          NSLog(@"touchesBegan");
      }
      

      然后你在上面的操作中处理下面的方法

      [super touchesBegan:touches withEvent:event];
      

      你的整体解决方案是这样的:

           #import "YourTextView.h" 
      
              @implementation YourTextView
      
              - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
          [super touchesBegan:touches withEvent:event];
      
       NSLog(@"touchesBegan");
              }
          - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
              NSLog(@"touchesEnded");
              [self.nextResponder touchesEnded: touches withEvent:event]; 
              NSLog(@"touchesEnded");
              [super touchesEnded:touches withEvent:event];
              NSLog(@"touchesEnded");
          }
      

      我希望这对你有帮助.. :)

      【讨论】:

        【解决方案5】:

        使用此代码这是委托

        <UITextFieldDelegate> 
        - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
        

        【讨论】:

          猜你喜欢
          • 2015-05-05
          • 1970-01-01
          • 1970-01-01
          • 2021-08-17
          • 1970-01-01
          • 2013-02-27
          • 1970-01-01
          • 2018-10-22
          • 2018-03-06
          相关资源
          最近更新 更多