Reputation: 5383
I have an UItextField in the last cell of the UITableView. My code to handle keyboard hiding :
func keyboardWillBeHidden(aNotification:NSNotification) {
let contentInsets: UIEdgeInsets = UIEdgeInsetsZero
tableView.contentInset = contentInsets
tableView.scrollIndicatorInsets = contentInsets
}
Works perfectly on iOS8 with a smooth animation. Moves back to its original position brutally on iOS7 (no animation) !
What's the solution on iOS7 ?
Upvotes: 0
Views: 338
Reputation: 722
I have done this before. Its in objective c. Check this -
- (void)keyboardWillHide:(NSNotification *)sender
{
NSTimeInterval duration = [[[sender userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
[UIView animateWithDuration:duration animations:^{
UIEdgeInsets edgeInsets = UIEdgeInsetsZero;
[_tableView setContentInset:edgeInsets];
[_tableView setScrollIndicatorInsets:edgeInsets];
}];
}
Upvotes: 1
Reputation: 2587
I would try this first. Adjust the animation duration to your preference.
UIView.animateWithDuration(0.2, animations: { () -> Void in
let contentInsets: UIEdgeInsets = UIEdgeInsetsZero
self.tableView.contentInset = contentInsets
self.tableView.scrollIndicatorInsets = contentInsets
})
Upvotes: 1