大佬教程收集整理的这篇文章主要介绍了iOS虚拟键盘大小没有通知中心,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我很熟悉
NSDictionary *info = [notification userInfo]; CGSize kbSize = [self.view convertRect: [info[UIKeyboardFrameBeginUserInfoKey] CGRectValue] fromView:nil].size;
但是,它对我不起作用,因为当用户点击可能半隐藏的文本字段时,我没有收到键盘通知.
所以我调用textFieldDidBeginEditing:中的方法,在键盘发送消息之前调用它,所以我不知道第一次点击时的KB大小.
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self selector:@selector(keyboardChangedStatus:) name:UIKeyboardWillShowNotification object:nil]; [nc addObserver:self selector:@selector(keyboardChangedStatus:) name:UIKeyboardWillHideNotification object:nil]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [nc removeObserver:self name:UIKeyboardWillHideNotification object:nil]; } #pragma mark - Get Keyboard size - (void)keyboardChangedStatus:(NSNotification*)notification { //get the size! CGRect keyboardRect; [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardRect]; keyboardHeight = keyboardRect.size.height; //move your view to the top,to display the textfield.. [self moveView:notification keyboardHeight:keyboardHeight]; } #pragma mark View Moving - (void)moveView:(NSNotification *) notification keyboardHeight:(int)height{ [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3]; [UIView setAnimationBeginsFromCurrentState:YES]; CGRect rect = self.view.frame; if ([[notification name] isEqual:UIKeyboardWillHideNotification]) { // revert back to the normal state. rect.origin.y = 0; hasScrolledToTop = YES; } else { // 1. move the view's origin up so that the text field that will be hidden come above the keyboard (you need to adjust the value here) rect.origin.y = -height; } self.view.frame = rect; [UIView commitAnimations]; }
以上是大佬教程为你收集整理的iOS虚拟键盘大小没有通知中心全部内容,希望文章能够帮你解决iOS虚拟键盘大小没有通知中心所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。