iOS新手入门之点击空白处回收键盘
2015-10-07 16:38
543 查看
首先需要建一个与屏幕等大的UIView, 然后把这个UIView添加到这个屏幕上, 把创建的UITextField作为UIView的子视图(添加到UIView上)
点击空白键盘回收使用下面方法就行
非常简单的点击空白实现键盘回收的方法
#import "AppDelegate.h" // 定义宏 设置成与屏幕等宽 方便使用 #define kScreenWidth [UIScreen mainScreen].bounds.size.width @interface AppDelegate () // 把view设置成属性, 便于下面方法的调用 @property (nonatomic, retain) UIView *view; @end @implementation AppDelegate - (void)dealloc { [_window release]; [super dealloc]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; // 初始化上面设置成属性的view self.view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; // 设置view的背景颜色为白色 self.view.backgroundColor = [UIColor whiteColor]; // 把view添加到window上 [self.window addSubview:self.view]; // 这点先不释放view 在下面释放view // 利用for循环 创建多个UITextField for (int i = 0; i < 3; i++) { UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake((kScreenWidth - 200) / 2, 100 + i * 80, 200, 50)]; textField.backgroundColor = [UIColor greenColor]; textField.font = [UIFont systemFontOfSize:22]; // 把textField添加到设置成属性的那个view上 [self.view addSubview:textField]; [textField release]; } // 释放view [self.view release]; [self.window makeKeyAndVisible]; return YES; }
点击空白键盘回收使用下面方法就行
非常简单的点击空白实现键盘回收的方法
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.view endEditing:YES]; }
相关文章推荐
- iOS ----Block语法
- iOS开发关闭NSLog在控制台不能够输出
- iOS-Quartz 2D
- iOS 经典笔记
- iOS-真机调试
- iOS-AFN相较ASI
- iOS数据持久化
- iOS-ASI
- iOS开发-XIB、Storyboard操作小技巧
- iOS开发零基础教程之真机调试流程
- iOS开发- 处理空字符串
- autoresizesSubviews
- IOS开发——多线程
- 如何把设计图自动转换为iOS代码? 在线等,挺急的!
- iOS中使用正则表达式去掉HTML中的标签元素获得纯文本的方法
- IOS使用XMPP最新教程(四)获取好友列表 (通过花名册)
- AVAudioSession、AVAudioRecorder、AVAudioPlayer
- iOS--关于AFN和ASI的post登录请求
- IOS开发笔记-01按钮操作-12.frame&bounds&center属性
- iOS异常处理机制