I have the following example which shows the issue.
I basically want to show a UI similar to iMessage where a UITextView is present at the bottom for typing the message.
Once the keyboard is shown in the UITextView, upon scrolling the UITableView even slightly, the content goes under the navigation bar while the navigation bar stays transparent. It seems like a weird UI bug.
import UIKit
import SnapKit
let numberOfRows = 15
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var myTableView: UITableView!
let textView = UITextView()
let bottomView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
myTableView.keyboardDismissMode = .interactive
bottomView.backgroundColor = .darkGray
bottomView.addSubview(textView)
view.addSubview(bottomView)
bottomView.snp.makeConstraints { make in
make.left.right.bottom.equalToSuperview()
make.height.equalTo(100)
}
textView.backgroundColor = .black
textView.snp.makeConstraints { make in
make.edges.equalToSuperview().inset(10)
}
textView.text = "Type something.."
}
override var inputAccessoryView: UIView {
return bottomView
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 200
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return numberOfRows
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")!
cell.textLabel?.text = "Row \(indexPath.row)"
cell.detailTextLabel?.text = "Tastes very close to Snickers chocolate bar. Only tried because of reviews. Would purchase again if price wasn’t so high, and available in Canada."
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
navigationController?.pushViewController(UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "DetailVC"), animated: true)
}
}
Screenshot of the bug after scrolling even a tiny bit after keyboard is shown: