首页 > 其他 > 详细

文本框输入与键盘隐藏

时间:2015-09-01 16:26:32      阅读:278      评论:0      收藏:0      [点我收藏+]

//移除通知

- (void)dealloc {

    [[NSNotificationCenter defaultCenter]removeObserver:nil];

}

 

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view from its nib.

    //添加tap手势

    self.tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidesKeyboard)];

    self.tapGesture.enabled = NO;//最开始手势设为no

    [self.view addGestureRecognizer:self.tapGesture];

 

    //键盘显示我用了通知结合手势来的

    //注册通知,

    [[NSNotificationCenter defaultCenter] addObserver:self

                                             selector:@selector(keyboardWillShow)

                                                 name:UIKeyboardWillShowNotification

                                               object:nil];

}

 //隐藏键盘

- (void)hidesKeyboard{

    [self.view endEditing:YES];

    self.tapGesture.enabled = NO;

}

 // 完成通知的方法就是把手势设为yes即可

- (void)keyboardWillShow {

    self.tapGesture.enabled = YES;

}

 

文本框输入与键盘隐藏

原文:http://www.cnblogs.com/now-or-never/p/4775783.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!