Вы можете попробовать это:
class YourView: UIView {
//setup your view...
}
protocol YourViewPresenter {
func showYourView()
func hideYourView()
}
extension YourViewPresenter where Self: UIViewController {
func showYourView() {
let yourView = YourView()
view.addSubview(yourView)
//after adding newly view, need to resize it
yourView.fillSuperview()
}
func hideYourView() {
(view.subviews.filter { $0 is PVInvitePopupView }).first?.removeFromSuperview()
}
}
extension UIView {
func fillSuperView() {
guard let superView = superview else { return }
translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
leadingAnchor.constraint(equalTo: superView.leadingAnchor, constant: 0),
trailingAnchor.constraint(equalTo: superView.trailingAnchor, constant: 0),
topAnchor.constraint(equalTo: superView.topAnchor, constant: 0),
bottomAnchor.constraint(equalTo: superView.bottomAnchor, constant: 0)
])
}
}
И затем просто настроить ваш TabBarController на это расширение:
extension UITabBarController: YourViewPresenter {}
//...
Затем вы можете вызвать showYourView()
где-то в вашем viewController, например:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.tabBarController?.showYourView()
}