我使用以下代码来确保当用户打开键盘时,它会缓慢打开并将 View 向上推。
func keyboardWasShown(notification: NSNotification){
tableViewChat?.tableView.isScrollEnabled = true
let info2 = notification.userInfo!
let keyboardFrame: CGRect = (info2[UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
UIView.animate(withDuration: 4, animations: { () -> Void in
self.bottomConstraint.constant = keyboardFrame.size.height - self.navigationController!.navigationBar.frame.height
})
}
到这里为止一切正常。现在我想在动画完成后执行这一行。
self.tableViewChat?.scrollToLastRow(animationBool: true)
如果动画没有完全执行,tableview 将无法向下滚动。执行动画后如何执行 scrollToLastRow?
感谢您的帮助和意见!
最佳答案
只需使用动画的完成 block 。
UIView.animate(withDuration: 4, animations: { () -> Void in
self.bottomConstraint.constant = keyboardFrame.size.height - self.navigationController!.navigationBar.frame.height
},completion{
self.tableViewChat?.scrollToLastRow(animationBool: true)
})
在动画完成之前,这不会滚动 tableview。在本例中为 4 秒。
关于iOS Swift 3 如何在动画完成后执行 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42737230/