Вот код, который я использую. используя:
Код: Выделить всё
let chatMainView = ChatScreenView(viewModel: chatViewModel)
let hostingController = UIHostingController(rootView: chatMainView)
addChild(hostingController)
self.view.addSubview(hostingController.view)
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
hostingController.view.keyboardLayoutGuide.usesBottomSafeArea = false // Works on iOS 17
NSLayoutConstraint.activate([
hostingController.view.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
hostingController.view.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
hostingController.view.topAnchor.constraint(equalTo: self.view.topAnchor),
hostingController.view.bottomAnchor.constraint(equalTo: self.view.keyboardLayoutGuide.topAnchor)
])
hostingController.didMove(toParent: self)
Как я могу добиться такого же поведения, скрывая нижнюю безопасную область, когда клавиатура отображается на iOS 15 и 16? Существует ли эквивалентный или альтернативный подход?
Подробнее здесь: https://stackoverflow.com/questions/790 ... hostingcon