即使有内容,View Controller 也会变黑

View Controller turning up black even though there is content

所以当我从另一个 View Controller 单击按钮时,它应该会显示下一个 View Controller。然而,当点击按钮时,它只显示下一个黑屏的 View Controller,即使上面有内容。我该如何解决这个问题?

我知道已经有人问过类似的问题,但 none 帮助我解决了这个问题。

按钮点击代码:

@IBAction func onSignUp(_ sender: Any) {
    presentDetail(SignUpViewController())
}

呈现下一个视图控制器和动画代码:

   extension UIViewController {


        func presentDetail(_ viewControllerToPresent: UIViewController) {
            let transition = CATransition()
            transition.duration = 0.25
            transition.type = CATransitionType.push
            transition.subtype = CATransitionSubtype.fromRight
            self.view.window!.layer.add(transition, forKey: kCATransition)

            self.present(viewControllerToPresent, animated: false)
        }

        func dismissDetail() {
            let transition = CATransition()
            transition.duration = 0.25
            transition.type = CATransitionType.push
            transition.subtype = CATransitionSubtype.fromLeft
            self.view.window!.layer.add(transition, forKey: kCATransition)

            dismiss(animated: false)
        }



}

澄清一下,presentDetail 函数假设用动画(从右开始)呈现下一个视图控制器,如代码中所示。

您需要在呈现之前从 Storyboard 实例化目标 ViewController。

@IBAction func onSignUp(_ sender: Any) {

presentDetail(

storyboard?.instantiateViewController(withIdentifier: "putyourIdentifierhere"))
}

实例化ViewController函数returns您要呈现的Viewcontroller。