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

How To Add One UIGestureRecognizer to All UITextView without blocking textView touches

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

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

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

只需使用UITextFieldDelegate方法或在UITextField下添加一个UIView并将gesture recognizer添加到UIView

这样试试:

- (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");
    }

希望对您有所帮助.. :)

使用此代码这是委托

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

首先你必须添加uitextfield委托

<UITextFieldDelegate> 

然后使用那个方法

(BOOL)textFieldShouldBeginEditing:(UITextField *) textField