【发布时间】:2015-08-01 02:18:41
【问题描述】:
我试图在显示键盘时滚动到 UIScrollView 的底部内容,但 setContentOffset 方法似乎不起作用。我在 Interface Builder 上使用 AutoLayout。也许这就是导致问题的原因?有什么想法吗?
当我的键盘显示时,我如何滚动到 UIScrollView 的底部。
P.S.:它会很好地显示 textField,我需要的是在显示键盘时显示 UIScrollView 的最底部
谢谢!!
下面是我当前的代码
func textFieldDidBeginEditing(textField: UITextField) {
var bottomOffset: CGPoint = CGPoint(x: 0, y: mainScrollView.contentSize.height - mainScrollView.bounds.size.height);
mainScrollView.setContentOffset(bottomOffset, animated: true);
}
func keyboardDidShow(notification: NSNotification) {
var userInfoDictionary: NSDictionary = notification.userInfo!;
var keyboardSize: CGSize = userInfoDictionary.objectForKey(UIKeyboardFrameBeginUserInfoKey)!.CGRectValue().size;
var contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: keyboardSize.height, right: 0);
mainScrollView.contentInset = contentInsets;
mainScrollView.scrollIndicatorInsets = contentInsets;
}
func keyboardWillHide(notification: NSNotification) {
var contentInsets = UIEdgeInsetsZero;
mainScrollView.contentInset = contentInsets;
mainScrollView.scrollIndicatorInsets = contentInsets;
}
【问题讨论】:
标签: ios swift uiscrollview uikeyboard