【发布时间】:2018-05-14 07:26:48
【问题描述】:
我知道有一些关于此主题的已发布问题,但没有一个有效。我有一个 tableview,在它下面有一个 UIView,其中包含一个文本字段和按钮。当我的键盘出现时,它覆盖了整个 UIView,使我无法单击“发送”。显示我的应用外观的图片:
目前,我的代码是:
override func viewDidLoad() {
super.viewDidLoad()
inputTextField.delegate = self
inputTextField.layer.cornerRadius = 5
inputTextField.clipsToBounds = true
sendButton.layer.cornerRadius = 5
sendButton.clipsToBounds = true
self.tableView.register(UINib(nibName: "TableViewCell", bundle: nil), forCellReuseIdentifier: "TableViewCell")
loadMsg()
self.hideKeyboardWhenTappedAround()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
inputTextField.becomeFirstResponder()
}
当我的键盘出现时,我应该如何将 UIView 连同 UIView 包含的文本字段和按钮一起向上移动?
【问题讨论】:
-
你应该使用inputAccessoryView,请找到这个question
-
你使用
AutoLayout来布局你的视图 -
是的,我是@AbdelahadDarwish
-
好的,我现在正在调查,@PPL
-
但是你解决了你的问题但是如果你需要键盘关闭就像苹果原生消息应用程序(向下拖动关闭)那么你应该实现这个stackoverflow.com/questions/50293919/…