【问题标题】:tableViewCell not scrolling up while editing a textfield in iOS11在iOS11中编辑文本字段时tableViewCell不会向上滚动
【发布时间】:2018-02-03 03:21:41
【问题描述】:

当我点击表格视图单元格中的文本字段并出现键盘时,单元格会自动向上滚动以使文本字段可见。这在 ios 10 中完美发生,但在 iOS 11 中却没有。有人有解决方案吗?

func displayKeyboard(_ notification: Notification) { 

    if let userInfo = notification.userInfo { 

        if let keyboardSize = (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue { 

            myTableView.contentInset = UIEdgeInsetsMake(0, 0, keyboardSize.height, 0) myTableView.scrollIndicatorInsets = myTableView.contentInset 

        }         
    }     
}

【问题讨论】:

  • func displayKeyboard(_ notification: Notification) { if let userInfo = notification.userInfo { if let keyboardSize = (userInfo[UIKeyboardFrameBeginUserInfoKey] as?NSValue)?.cgRectValue { myTableView.contentInset = UIEdgeInsetsMake(0, 0,keyboardSize.height,0) myTableView.scrollIndicatorInsets = myTableView.contentInset } } }
  • 是否可以附加您的项目
  • 我不认为这是可能的。根据我的观察,当键盘通知被触发时,(UIKeyboardFrameBeginUserInfoKey)给我键盘的高度为0。

标签: ios uitableview swift3 uitextfield ios11


【解决方案1】:

替换UIKeyboardFrameBeginUserInfoKey

UIKeyboardFrameEndUserInfoKey.

希望它有效。

【讨论】:

猜你喜欢
  • 2012-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多