gpt4 book ai didi

iOS 在 UINavigationController 中用键盘移动 ToolBar

转载 作者:行者123 更新时间:2023-11-28 18:36:46 25 4
gpt4 key购买 nike

我要疯了。当键盘出现时,我将尝试移动工具栏及其文本字段。使用以下代码, View 确实在移动,但工具栏保持不变并被键盘隐藏:

- (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:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardFrame];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:animationDuration];
[UIView setAnimationCurve:animationCurve];

[self.view setFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y - keyboardFrame.size.height, self.view.frame.size.width, self.view.frame.size.height)];

[UIView commitAnimations];
}

我是初学者所以请不要打我,但我不知道缺少的链接来移动和显示工具栏及其文本字段。

工具栏和文本框是在 viewDidLoad 方法中创建的。

最佳答案

我发现 ToolBar 本身必须随键盘移动:这可以防止它被出现的键盘隐藏:

enter image description here

在 NavigationController 中使用 ToolBar 时,以下代码应该可以解决问题:

- (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];

}

所有其他必要的代码都得到了很好的描述 HERE .

关于iOS 在 UINavigationController 中用键盘移动 ToolBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17391113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com