首页 > 解决方案 > 如何:为 UIViewController 将 UIModalPresentationStyle 从 .automatic 更改为 .fullscreen

问题描述

我尝试modalPresentationStyle按照 Apple 文档设置为 .fullscreen。

设置modalPresentationStyle.fullscreen如下代码所示后,系统仍以UIModalPresentationStyle.automatic“系统默认值”呈现视图控制器

//Presentation Style
let homeVC = HomeController(viewModel: viewModel)
homeVC.modalPresentationStyle = UIModalPresentationStyle.fullScreen

一个名为 XCoordinator 的框架控制此应用程序中的导航,这里是一个如何完成的示例。

switch route { 
case .home: 

let viewModel = HomeViewModelImpl(router: anyRouter) 
let viewController = HomeController(viewModel: viewModel) 

return .push(viewController)

}

标签: iosswiftrx-swiftios13uimodalpresentationstyle

解决方案


设置XCoordinatorTabBarCoordinator时有一个 rootViewController。

这里的解决方案是.modalPresentationStyle将..fullscreenrootViewController

rootViewController.modalPresentationStyle = .fullscreen

注意,这必须super在类文件中的任何方法之后调用


推荐阅读