码迷,mamicode.com
首页 > 移动开发 > 详细

IOS单击背景推出键盘

时间:2014-06-27 16:40:09      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   tar   color   

1. 手势(触背景)关闭键盘

在ViewDidLoad中调用

-(void)tapBackground //在ViewDidLoad中调用
{
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnce)];//定义一个手势
    [tap setNumberOfTouchesRequired:1];//触击次数这里设为1
    [self.view addGestureRecognizer:tap];//添加手势到View中
}

-(void)tapOnce//手势方法
{
[self.view endEditing:YES];
}

2. 直接关闭

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

 

 

IOS单击背景推出键盘,布布扣,bubuko.com

IOS单击背景推出键盘

标签:style   class   blog   code   tar   color   

原文地址:http://www.cnblogs.com/sosomaxba/p/3810020.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!