ios中怎么设置textfield点击其他地方键盘收回

ios中怎么设置textfield点击其他地方键盘收回,第1张

//在点击需要收回键盘的视图添加单击手势

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(reKeyBoard)]

[self.view addGestureRecognizer:tap]

//实现方法//取消textView ,textField的第一响应者即可

- (void)reKeyBoard

{

[_introduceGroupField resignFirstResponder]

[_nameGroupField resignFirstResponder]

}

UIScrollView本身无法处理touch事件要想实现,必须对UIScrollView上的subView做touch处理原理十分简单,好比要响应scrollView上的UIImageView,那么请创建一个UIImageVIew的子类,由这个自定义的UIImageView来处理touch事件头文件声明如下,供参考:#import @protocol ImageTouchDelegate-(void)imageTouch:(NSSet *)touches withEvent:(UIEvent *)event whichView:(id)imageView@end@interface ImageTouchView : UIImageView { id delegateBOOL delegatrue}@property(nonatomic,assign)id delegate@end这个是头文件,源文件可以是这个这样子@implementation ImageTouchView@synthesize delegate-(id)initWithFrame:(CGRect)frame{ if (self == [super initWithFrame:frame]) { [self setUserInteractionEnabled:YES]delegatrue=YES} return self}- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view{ return YES}-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ if (delegatrue) { [delegate imageTouch:touches withEvent:event whichView:self]}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11285371.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存