UIScrollView
固定在控制器的视图边缘。
在UIKeyboardWillShow
上,我通过增加键盘高度来增加contentInsets
的底值。动画制作完成后,内容将向上滚动一点。
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
let duration = notification.userInfo?[UIKeyboardAnimationDurationUserInfoKey] as? Double ?? 0.3
self.formContainer.contentInset = UIEdgeInsets(top: self.rowPadding, left: 0, bottom: keyboardSize.height + self.navigator.frame.height + 10, right: 0)
self.navigatorBottom.constant = -keyboardSize.height
UIView.animate(withDuration: duration) {
self.view.layoutIfNeeded()
}
}
是否仍然在此处禁用内容滚动?
答案 0 :(得分:0)
在开始动画之前保存contentOffset
中的UIScrollView
,并在动画contentOffset
中将保存的值设置为completionHandler
看起来像这样:
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
let duration = notification.userInfo?[UIKeyboardAnimationDurationUserInfoKey] as? Double ?? 0.3
let currentContentOffset = self.formContainer.contentOffset.y //assume your scrollView scrolls vertically
self.formContainer.contentInset = UIEdgeInsets(top: self.rowPadding, left: 0, bottom: keyboardSize.height + self.navigator.frame.height + 10, right: 0)
self.navigatorBottom.constant = -keyboardSize.height
UIView.animate(withDuration: duration, animations: {
self.view.layoutIfNeeded()
}) { _ in
self.formContainer.contentOffset.y = currentContentOffset
}
}