当键盘在iOS中显示时,无法滚动到视图底部

当键盘在iOS中显示时,无法滚动到视图底部,ios,objective-c,Ios,Objective C,有一个分段控件,每个控件具有不同的高度。它们中的每一个都有一些文本字段。当我点击文本字段,然后点击另一段时,我无法在显示键盘时滚动到视图底部。 我想用这些不起作用的代码来解决这个问题 if(self.isKeyBoardShowing) { CGRect borderLabelRect = containerView.frame; self.scrollView.contentSize = CGSizeMake(borderLabelRect.size.width , borde

有一个分段控件,每个控件具有不同的高度。它们中的每一个都有一些文本字段。当我点击文本字段,然后点击另一段时,我无法在显示键盘时滚动到视图底部。
我想用这些不起作用的代码来解决这个问题

if(self.isKeyBoardShowing) {
    CGRect borderLabelRect = containerView.frame;
    self.scrollView.contentSize = CGSizeMake(borderLabelRect.size.width , borderLabelRect.size.height + 325);
    [self.view layoutIfNeeded];
    [self.view layoutSubviews];
}

删除您为键盘设置所做的代码

只需将IQKeyboard manager粘贴到项目中,它就会自动滚动

从下面的链接下载


删除您为键盘设置所做的代码

只需将IQKeyboard manager粘贴到项目中,它就会自动滚动

从下面的链接下载


在viewDidLoad中添加观察者

NotificationCenter.default.addObserver(self, selector: #selector(onShowKeyboard), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
并将选择器设置为->

 @objc func onShowKeyboard(_ notification:Notification) {

    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
        self.scrollView.contentInset = UIEdgeInsetsMake(0, 0, keyboardSize.height, 0)
    }
}

在viewDidLoad中添加观察者

NotificationCenter.default.addObserver(self, selector: #selector(onShowKeyboard), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
并将选择器设置为->

 @objc func onShowKeyboard(_ notification:Notification) {

    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
        self.scrollView.contentInset = UIEdgeInsetsMake(0, 0, keyboardSize.height, 0)
    }
}

有滚动视图吗?最好在主视图后添加UIScrollView。有滚动视图吗?最好在主视图后添加UIScrollView。他需要目标中的代码che需要目标c中的代码