【问题标题】: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