动态获取键盘高度
2015-09-09 17:24
330 查看
动态获取键盘高度:
//需要手动调用 registerForKeyboardNotifications 方法,其他两个会自动调用,弹出的键盘高 216(输入英文时候),ios 5 系统的 @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [self registerForKeyboardNotifications]; UITextView *tv = [[UITextView alloc] initWithFrame:CGRectMake(100, 100, 100, 50)]; [self.view addSubview:tv]; [tv release]; } - (void) registerForKeyboardNotifications { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasHidden:) name:UIKeyboardDidHideNotification object:nil]; } - (void) keyboardWasShown:(NSNotification *) notif { NSDictionary *info = [notif userInfo]; NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey]; CGSize keyboardSize = [value CGRectValue].size; NSLog(@"keyBoard:%f", keyboardSize.height); //216 ///keyboardWasShown = YES; } - (void) keyboardWasHidden:(NSNotification *) notif { NSDictionary *info = [notif userInfo]; NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey]; CGSize keyboardSize = [value CGRectValue].size; NSLog(@"keyboardWasHidden keyBoard:%f", keyboardSize.height); // keyboardWasShown = NO; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- vi常用到的命令
- 小白写爬虫之第一天
- boot.img提取
- Unity3D开发之Unity跟IOS交互过程
- zookeeper启动没发现错误,但是是失败的
- 题目:求s=a+aa+aaa+aaaa+aa...a的值
- phoneGap+iOS环境搭建
- 0909 编译原理1
- ACM学习历程—FZU2191完美的数字(数学)
- 0909编译原理
- 0909有关编译原理的解释
- 0909 编译原理第1次上机作业
- JConsole & JVisualVM远程监视Websphere服务器JVM的配置方法
- 内存管理
- java中的值传递和引用传递
- Notice: Undefined index: ... 问题的解决方案
- Qt 信号槽机制与事件机制四 提升篇
- sqlserver 与mysql的小区别
- 一维数组,冒泡排序(Day-3)
- UC/OS II事件管理(2)之信号量管理