Answer the question
In order to leave comments, you need to log in
How to scroll UITableView on height change?
func keyboardWillShow(sender: NSNotification) {
let duration = sender.userInfo![UIKeyboardAnimationDurationUserInfoKey] as! Double
let curve = sender.userInfo![UIKeyboardAnimationCurveUserInfoKey] as! UInt
let info: NSDictionary = sender.userInfo!
let value: NSValue = info.valueForKey("UIKeyboardFrameEndUserInfoKey") as! NSValue
let keyboardSize: CGSize = value.CGRectValue().size
UIView.animateWithDuration(duration, delay: 0, options: UIViewAnimationOptions(rawValue: curve), animations: {
self.contentBottomConstrains.constant = keyboardSize.height
self.tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: self.messages.count-1, inSection: 0), atScrollPosition: UITableViewScrollPosition.Top, animated: true)
self.view.layoutIfNeeded()
}, completion: nil)
}
Answer the question
In order to leave comments, you need to log in
Transfer the code
in completionBlock.
Now at the time of the call, the table still has the old dimensions. At the same time, scrollToRow.... will create the animation on its own.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question