Взгляните на пример проекта iOS Firechat на Github. Он использует текстовое поле вне таблицыView и перемещает представление вместе с клавиатурой, когда она появляется/исчезает.
В частности в этом разделе:
// Setup keyboard handlers to slide the view containing the table view and
// text field upwards when the keyboard shows, and downwards when it hides.
- (void)keyboardWillShow:(NSNotification*)notification
{
[self moveView:[notification userInfo] up:YES];
}
- (void)keyboardWillHide:(NSNotification*)notification
{
[self moveView:[notification userInfo] up:NO];
}
- (void)moveView:(NSDictionary*)userInfo up:(BOOL)up
{
CGRect keyboardEndFrame;
[[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]
getValue:&keyboardEndFrame];
UIViewAnimationCurve animationCurve;
[[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey]
getValue:&animationCurve];
NSTimeInterval animationDuration;
[[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]
getValue:&animationDuration];
// Get the correct keyboard size to we slide the right amount.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:animationDuration];
[UIView setAnimationCurve:animationCurve];
CGRect keyboardFrame = [self.view convertRect:keyboardEndFrame toView:nil];
int y = keyboardFrame.size.height * (up ? -1 : 1);
self.view.frame = CGRectOffset(self.view.frame, 0, y);
[UIView commitAnimations];
}
Вот то же самое в Swift, непроверенных:
func moveView(userInfo : NSDictionary, up : Bool){
var keyboardEndFrame : CGRect?
userInfo.objectForKey(UIKeyboardFrameEndUserInfoKey)?.getValue(&keyboardEndFrame)
var animationCurve : UIViewAnimationCurve?
userInfo.objectForKey(UIKeyboardAnimationCurveUserInfoKey)?.getValue(&animationCurve)
var animationDuration : NSTimeInterval?
userInfo.objectForKey(UIKeyboardAnimationDurationUserInfoKey)?.getValue(&animationDuration)
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationBeginsFromCurrentState(true)
UIView.setAnimationDuration(animationDuration!)
UIView.setAnimationCurve(animationCurve!)
let keyboardFrame = self.view.convertRect(keyboardEndFrame!, toView: nil)
let y = keyboardFrame.size.height * (up ? -1 : 1);
self.view.frame = CGRectOffset(self.view.frame, 0, y);
UIView.commitAnimations()
}
проверить это. http://creativecoefficient.net/swift/keyboard-management/ ==> Теоретически только нужно изменить 'scrollView' для вашего' tableview' – jose920405