Я использую уведомление, чтобы придать вид снизу, чтобы придумать клавиатуру.
Я дал ограничения вида снизу в раскадровке, как показано ниже:
bottom to safe area = 0, leading, trailing = 0 , height = 80
i phone8 это идет хорошо, но в iphone11 становится промежуток между видом снизу и снизу устройства, , поэтому, если я изменю ограничение дна на 0 для суперпредставления, вид снизу не подходит для клавиатуры
![enter image description here](https://i.stack.imgur.com/wGMVH.png)
![enter image description here](https://i.stack.imgur.com/P78uO.png)
вот код:
class ChatViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var bottomConstraint: NSLayoutConstraint!
@IBOutlet weak var customView: UIView!
@IBOutlet weak var msgTextField: UITextField!
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification), name: UIResponder.keyboardWillHideNotification, object: nil)
}
override func viewWillDisappear(_ animated: Bool) {
NotificationCenter.default.removeObserver(self)
}
@objc func handleKeyboardNotification(_ notification: Notification) {
if let userInfo = notification.userInfo {
let keyboardFrame = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as AnyObject).cgRectValue
let isKeyboardShowing = notification.name == UIResponder.keyboardWillShowNotification
bottomConstraint?.constant = isKeyboardShowing ? -keyboardFrame!.height : 0
UIView.animate(withDuration: 0.5, animations: { () -> Void in
self.view.layoutIfNeeded()
})
}
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.customView.superview?.setNeedsLayout()
//self.customView.superview?.layoutIfNeeded()
}
}
пожалуйста, помогите мне.