它通常并不好把一个文本字段中输入附件视图......如果你把工具栏沿视图的底部,然后用UIKeyboardWillChangeFrameNotification
使用键盘移动工具栏什么是更好的是.. 。
在您的viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChange:) name:UIKeyboardWillChangeFrameNotification object:nil];
在您的视图控制器的代码
而且地方:
-(void) keyboardWillChange:(NSNotification*)notify {
CGRect endFrame;
float duration = [[[notify userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
[[[notify userInfo] valueForKey:UIKeyboardFrameEndUserInfoKey] getValue:&endFrame];
endFrame = [self.view convertRect:endFrame fromView:nil];
float y = (endFrame.origin.y > self.view.bounds.size.height ? self.view.bounds.size.height-44 : endFrame.origin.y-44);
[UIView animateWithDuration:duration animations:^{
toolbar.frame = CGRectMake(0, y, self.view.bounds.size.width, 44);
}];
}
这似乎像什么内置的消息应用程序与做文本输入工具栏。 – Dima
是的,我认为是的,它也是一个简单的移动全屏滚动视图,文本视图或Web视图的方法,这样即使键盘覆盖它也可以滚动到结尾... – jjv360
在这种情况下,是endFrame在那里确保我将工具栏向正确的方向移动? (当键盘在消失时上下移动时)? –