现在的位置: 首页 > 综合 > 正文

点击屏幕任意位置隐藏虚拟键盘

2019年10月02日 ⁄ 综合 ⁄ 共 421字 ⁄ 字号 评论关闭

转自:http://blog.csdn.net/xys289187120/article/details/6831917#

在视图底部添加一个透明按钮,这里假定有一个textfield. 在编辑textField时会弹出虚拟键盘,现在通过添加的透明按钮在隐藏虚拟键盘。

//创建一个隐藏的按钮
backgroudButton=[[UIButton alloc] init];
//让这个填充整个屏幕
backgroudButton.frame = self.view.frame; 
//添加按钮的响应时间,用来关闭软键盘
[backgroudButton addTarget:self action:@selector(ButtonClick) forControlEvents:UIControlEventTouchUpInside]; 

-(void)ButtonClick
{ 
    // 触摸屏幕人以地方 关闭软键盘
    [textfield resignFirstResponder];
}

抱歉!评论已关闭.