为何创建普通Segue跳转ViewController时,在leagueVC中无法全屏显示?
解决Segue跳转ViewController无法全屏的问题
方法一:通过Storyboard可视化设置
- 选中你创建的Segue,打开右侧的Attributes Inspector面板
- 将Segue的类型从默认的
Show改为Present Modally - 在Presentation下拉选项里选择
Full Screen,这样跳转后的ViewController就会全屏展示 - 若需要关闭全屏界面,在目标ViewController里给按钮添加点击事件,调用代码:
self.dismiss(animated: true)
方法二:通过代码动态设置
- 先给Segue设置一个唯一的Identifier(比如
toFullScreenVC),在Storyboard的Segue属性里完成配置 - 在leagueVC中重写
prepare(for:sender:)方法:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { guard segue.identifier == "toFullScreenVC" else { return } let destVC = segue.destination destVC.modalPresentationStyle = .fullScreen }
- 也可以直接用代码触发全屏跳转(无需依赖Storyboard Segue):
// 替换成你的目标ViewController的标识符 if let targetVC = storyboard?.instantiateViewController(withIdentifier: "TargetVC") { targetVC.modalPresentationStyle = .fullScreen present(targetVC, animated: true) }
内容的提问来源于stack exchange,提问作者Ameer AG
相关产品推荐
相关产品推荐

