M
M
Maxim Vlasov2015-10-13 22:27:42
iOS
Maxim Vlasov, 2015-10-13 22:27:42

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)
        
    }

This code changes the padding from the bottom of the superview, raising the input field to the height of the keyboard, but does not want to scroll the table down. Please help me find and fix the error.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Beltyukov, 2015-10-18
@maestrro712

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 question

Ask a Question

731 491 924 answers to any question