在UITableView和GoogleMap的View上开始触摸时关闭键盘 [英] Dismiss Keyboard when touch began on UITableView and GoogleMap's View

查看:87
本文介绍了在UITableView和GoogleMap的View上开始触摸时关闭键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目设计:

UINavigationController ---> UITableViewController ---> UIViewController

我在navigationItem.titleView上有UISeachBar

我尝试使用UITapGestureRecognizer,它可以正常工作,但没有达到预期的效果.仅当我触摸UITableViewCell时,键盘才会关闭.

I tried to use UITapGestureRecognizer, it works but not as expected. Keyboard only dismisses when I touch on an UITableViewCell.

我希望UITableView响应touchesBegan,以便我每次触摸UITableViewCell或只是在桌子上滚动时都可以使键盘消失.

I want UITableView responds to touchesBegan so that I could make the keyboard disappears whenever I touch on an UITableViewCell or just scroll on the table.

此外,我的UIViewController包含一个googlemap的视图,它确实对touchesBegan做出了响应,但只有一次触摸,此后,其他所有触摸都将被忽略.

Besides that, my UIViewController contains a googlemap's View, it does respond to touchesBegan but only one first touch, after that, every other touches would be ignored.

有人可以帮忙吗?

时间太长,没有读过:我想像Safari或chrome一样关闭UITableView上的虚拟键盘:触摸何时开始而不是何时结束

too long, didn't read: i want to dismiss the virtual keyboard on UITableView likes safari or chrome: when the touch began, not when it ended

推荐答案

尝试像这样创建UITableView的子类:

Try creating a subclass of UITableView like so:

subclassTB.h

 #import <UIKit/UIKit.h>

@interface subClassTB : UITableView

@end


subclassTB.m
#import "subclassTB.h"


 @implementation subClassTB

 - (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    // do your stuff here 
    //NSLog(@"tap registered");
    [super touchesBegan:touches withEvent:event];
}
@end

,然后在您当前的控制器中使用来初始化表

and in your current controller initialize the table by using

subclassTB *yourtable = [[subclassTB alloc]initWithFrame:youFrame style:yourStyle];

这篇关于在UITableView和GoogleMap的View上开始触摸时关闭键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆