【问题标题】:2.Page ViewController are not fullscreen?2.Page ViewController 不是全屏的?
【发布时间】:2021-06-24 17:17:59
【问题描述】:

我现在正在使用我的第一个 swift 应用程序。我想制作 2 页。

1.Page -> 按钮 -> 2.Page

它可以工作,但 2.Page 看起来不像全屏?!更像是要滑动的页面? 我想要一个正常的 2.Page 像第一个。希望你知道我的意思 :D 谢谢你的帮助。 enter image description here

enter image description here

【问题讨论】:

  • 你的意思是你想让第二个视图控制器滑入并有一个后退按钮?你可以使用 UINavigationController 和 push
  • 是的,这就是我想要的 xD 我用 UINavigationController 搜索视频。谢谢你:)

标签: ios swift iphone view viewcontroller


【解决方案1】:

如果您的 SecondViewController 是在没有情节提要的程序代码中创建的,则以下代码将毫无问题地运行

解决方案 1:

class FirstController: UIViewController {

    func presentSecondController() {
        // create instance of secondVC
        let secondController = UIViewController(nibName: nil, bundle: nil)      

        // Change presentation style
        secondController.modalPresentationStyle = .fullScreen

        // Present secondVC
        self.present(secondController, animated: true, completion: nil)
    }
}

`

解决方案 2:

2.a 如果在情节提要中创建了 SecondViewController,则必须将 StoryboardID 添加到您的 SecondViewController,如下图所示:

2.b 通过添加以下代码从情节提要中实例化 secondController 实例:

class FirstController: UIViewController {

    func presentSecondController() {

        // Create storyboard instance from name file
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        
        // Instantiate secondVC from storyboardID
        guard let secondController = storyboard.instantiateViewController(withIdentifier: "secondControllerID") as? SecondController else { return }

        // Change presentation style
        secondController.modalPresentationStyle = .fullScreen

        // Present secondVC
        self.present(secondController, animated: true, completion: nil)  
    }

}

【讨论】:

  • 嘿,感谢您的帮助和您的时间!我现在在故事板上。但我想我必须用代码来做。我对多个 ViewController 有一些问题 .. 1. 是全屏视图而不是连接视图。我试试你给我发的短信:)
  • 你有 Discord 或 ts 吗?哈哈。我想我弄错了第二个 ViewController ?!这可能吗? xD
【解决方案2】:

您只需转到故事板选择第二个视图控制器并将演示样式更改为“全屏”。请参考这里

【讨论】:

  • 嘿,感谢您的帮助和您的时间 :) 我尝试了一下...但没有任何反应?同样的看法?我究竟做错了什么 ? :(
  • 你是否使用 segue 显示另一个控制器?
  • idk 如何给你发一张照片,我在我的问题中添加了一张新照片。我对 swift 很抱歉 -.- 我想是的 xD 我使用 segue。
  • 好的,我把它改成 ,,SHOW, 就可以了。 :D 现在我可以制作一个后退按钮,我认为它完成了 xD 现在我正在等待下一个问题 :D 非常感谢 :)
  • 很高兴为您提供帮助,请 UpVote 回答,这样它也可以帮助贡献者
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-19
  • 2011-12-11
  • 2015-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多