You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS开发求助:跳转ViewController后视图显示异常问题

问题:视图跳转后无法全屏显示,状态异常

初始视图(点击按钮后应弹出下一视图):
初始视图

异常显示的视图(本该占满整个屏幕):
异常显示的视图

相关代码

import UIKit

class Onboarding_Screen_One: UIViewController {

    @IBOutlet weak var First_button: UIButton!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
    
    @IBAction func Button_Tapped(_ sender: UIButton) {
        print("Next button tapped on OnBoarding_Screen_One.")
        
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        if let onboardingScreenTwoVC = storyboard.instantiateViewController(withIdentifier: "Onboarding_Screen_Two") as? Onboarding_Screen_Two {
            self.present(onboardingScreenTwoVC, animated: true, completion: nil)
        }
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */
}

问题描述

恳请各位帮忙解释为何视图会呈现此状态,且无法正常跳转到新的ViewController?
我已经通过谷歌搜索和AI工具尝试解决,但视图始终无法正常显示


可能的原因及修复方案

  • Modal展示样式问题:iOS 13及以上默认的modalPresentationStyle是.pageSheet,会以半屏形式展示。要实现全屏显示,在present视图控制器前添加一行代码:
    onboardingScreenTwoVC.modalPresentationStyle = .fullScreen
    
  • Storyboard视图尺寸配置错误:打开Main.storyboard,选中Onboarding_Screen_Two,检查右侧属性面板的「Simulated Metrics」-「Size」,确保设置为「Inferred」,而非固定尺寸或Freeform。
  • Storyboard ID不匹配:确认Onboarding_Screen_Two的Storyboard ID与代码中"Onboarding_Screen_Two"完全一致,包括大小写。
  • Auto Layout约束缺失:检查Onboarding_Screen_Two的根视图是否添加了完整的约束(比如顶部、底部、左侧、右侧均绑定到父视图边缘),约束不完整会导致视图无法铺满屏幕。

内容的提问来源于stack exchange,提问作者Matthew_A

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 08:05:13