【发布时间】:2013-07-01 19:42:00
【问题描述】:
我想出了如何使用出现的键盘移动带有按钮和文本字段的工具栏:
- (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];
}
一切正常,但移动的工具栏和键盘之间有一个小间隙:
我无法找出问题所在?可能是什么问题或者是预期的行为?
谢谢!
【问题讨论】:
-
我建议检查该空间是否实际上不是工具栏图像的一部分。并且还尝试首先对工具栏的位置进行硬编码,然后检查您的计算值并进行比较(更容易找到问题)。此外,如果您使用自动布局,请检查约束。
-
你好,丹尼帕塔。感谢您的回答。 1.空间如何成为工具栏的一部分?工具栏是我的导航控制器的一部分。 2. 我去看看。好主意。 3. 我也会检查一下,但布局会出现什么问题?谢谢!
标签: ios uitoolbar keyboard-events