Есть идеи, что я могу делать неправильно? Он отлично работает в SwiftUI, и ни одно из системных приложений не ведет себя одинаково.

Я создаю контроллер представления в своем SceneDelegate следующим образом:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let windowScene = (scene as? UIWindowScene) else { return }
window = .init(windowScene: windowScene)
let tabVC = Self.makeTabVC()
window?.rootViewController = tabVC
window?.makeKeyAndVisible()
}
static func makeTabVC() -> UIViewController {
let tabVC = UITabBarController(tabs: [
.init(title: "View 1", image: .init(systemName: "1.circle"), identifier: "Tab.vc1", viewControllerProvider: { _ in
return ViewController(text: "View 1", color: .systemBackground)
}),
.init(title: "View 2", image: .init(systemName: "2.circle"), identifier: "Tab.vc2", viewControllerProvider: { _ in
return ViewController(text: "View 2", color: .blue)
})
])
return tabVC
}
Мой код ViewController:
class ViewController: UIViewController {
convenience init(text: String, color: UIColor) {
self.init(nibName: nil, bundle: nil)
self.text = text
self.color = color
}
var text: String!
var color: UIColor!
private var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
label = UILabel()
view.addSubview(label)
label.center = view.center
label.translatesAutoresizingMaskIntoConstraints = false
label.text = text
label.sizeToFit()
NSLayoutConstraint.activate([
label.centerXAnchor.constraint(equalTo: view.centerXAnchor),
label.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])
view.backgroundColor = color
// Do any additional setup after loading the view.
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... -in-ios-26
Мобильная версия