iOS为什么将ToolBar的差距移到了键盘上 [英] iOS why has moved ToolBar gap to keyboard
本文介绍了iOS为什么将ToolBar的差距移到了键盘上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想出了如何使用出现的键盘来移动带有按钮和文本字段的工具栏:
I figured out how to move my toolbar with button and text field with the appearing keyboard:
- (void) liftMainViewWhenKeybordAppears:(NSNotification*)aNotification
{
NSDictionary* userInfo = [aNotification userInfo];
NSTimeInterval animationDuration;
UIViewAnimationCurve animationCurve;
CGRect keyboardFrame;
[[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
[[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
[[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] getValue:&keyboardFrame];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:animationDuration];
[UIView setAnimationCurve:animationCurve];
[self.navigationController.toolbar setFrame:CGRectMake(self.navigationController.toolbar.frame.origin.x,
self.navigationController.toolbar.frame.origin.y - keyboardFrame.size.height +self.navigationController.toolbar.frame.size.height,
self.navigationController.toolbar.frame.size.width,
self.navigationController.toolbar.frame.size.height)];
[UIView commitAnimations];
}
一切正常,但移动的工具栏和键盘之间有一个小缝隙:
Everything works fine but there is a small gap between the moved toolbar and the keyboard:
我不知道是什么问题?可能是问题还是预期的行为?
and I can't figure out the problem? What could be the problem or is that the expected behavior?
谢谢!
推荐答案
请尝试以下操作来计算新的帧大小:
Try the following for calculating the new frame size:
CGRect kbFrameBegin;
[[userInfo valueForKey:UIKeyboardFrameBeginUserInfoKey] getValue: &kbFrameBegin];
CGRect kbFrameEnd;
[[userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &kbFrameEnd];
CGRect frame = self.navigationController.toolbar.frame;
frame.size.height -= abs(kbFrameBegin.origin.y - kbFrameEnd.origin.y);
[self.navigationController.toolbar setFrame:frame];
这篇关于iOS为什么将ToolBar的差距移到了键盘上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文