iOS 之点击背景退出键盘
来源:互联网 发布:彩票数据导出 编辑:程序博客网 时间:2024/05/22 06:13
原博地址:iOS 之点击背景退出键盘
注释:UITextFiled才有输入框,所以先建立一个UITextFiled对象,点击他会出现输入框,利用UITapGestureRescognizer 类实现操作,上代码:
.h文件中不用操作
//
// LYXViewController.h
// UITap
//
// Created by liyongxing on 13-7-6.
// Copyright (c) 2013年 liyongxing. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LYXViewController : UIViewController
@end
//
// LYXViewController.m
// UITap
//
// Created by liyongxing on 13-7-6.
// Copyright (c) 2013年 liyongxing. All rights reserved.
//
#import "LYXViewController.h"
@interface LYXViewController ()
@property (nonatomic,strong) UITextField * text;
@end
@implementation LYXViewController
-(void)viewDidLoad
{
[super viewDidLoad];
//创建UITextField的对象,并给他定位制定大小,位置
self.text = [[UITextField alloc]initWithFrame:CGRectMake(50, 50, 200, 60)];
//设置背景色,默认为透明色
self.text.backgroundColor = [UIColor grayColor];
//将对象添加到视图上
[self.view addSubview:self.text];
//调用点击背景方法
[self tapGesture];
}
-(void)tapGesture
{
//创建一个点击对象,并将其关联一个点击方法
UITapGestureRecognizer * tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:selfaction:@selector(tapResign)];
//设置点击多少次退出键盘,一般设置为1次
tapGestureRecognizer.numberOfTapsRequired = 1.0;
//将点击对象添加到当前视图
[self.view addGestureRecognizer:tapGestureRecognizer];
//是否取消点击背景视图的动作,设置为否
[tapGestureRecognizer setCancelsTouchesInView:NO];
}
//点击背景视图的时候发生的时间,退出第一响应者,到此就能完成我们想要的效果
-(void)tapResign
{
[self.text resignFirstResponder];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
转自:http://blog.csdn.net/u011199592/article/details/9260613
- iOS 之点击背景退出键盘
- iOS 之点击背景退出键盘
- iOS 之点击背景退出键盘
- ios点击空白界面退出键盘问题。
- IOS-Controller中点击屏幕退出键盘
- ios菜鸟之路:textfield隐藏键盘以及点击背景取消键盘
- ios点击背景时关闭键盘
- iOS关闭键盘 return 或者 点击背景
- iOS点击空白处或点击背景收起键盘
- iOS点击空白处或点击背景收起键盘
- 点击屏幕键盘退出
- 点击键盘周边退出键盘
- 点击背景 键盘下去
- 点击背景 关闭键盘
- 点击背景关闭键盘
- ios点击屏幕实现退出键盘的功能
- ios uitableview里点击界面退出键盘的实现
- iOS——点击背景取消键盘的方法
- oracle 导出导入
- 自动生成ACM-ICPC模版的Latex版本
- Rapid compile好用了
- JPA工程配置persistence.xml参数详解
- Ubuntu下MySQL数据库错误解决:ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)
- iOS 之点击背景退出键盘
- Ubuntu关闭T440P的touchpad
- Android字符串 特殊字符的输入
- MongoDB基本使用
- android如何调用显示和隐藏系统默认的输入法
- 深入剖析Android四大组件(六)——相对完美的后台Service实现播放音乐功能
- 程序员鼓励师?阿里巴巴被批低俗,股价下降
- Android屏幕适配全攻略(最权威的官方适配指导)
- sql学习笔记(1)-------------学习基础