转换后的视图控制器是适合其大小类的限制,而不是设备

问题描述:

首先,我遵循本教程:https://www.youtube.com/watch?v=B9sH_VxPPo4,然后我在一个真正的项目中使用此过渡,我工作,但自那时起,我面临一个问题它。一个我不明白为什么会发生的问题。也许你可以帮助我。转换后的视图控制器是适合其大小类的限制,而不是设备

发生了什么是以下几点:我正在为使用此转换的应用程序制作教程。在设置教程文本的视图控制器中,我将顶部,底部,前导和尾部约束设置为0.因此,它应该将视图控制器适合边缘,对吧?但只有当我在尺寸类中选择了我在模拟器中使用的相同设备时才会发生这种情况。例如,我必须运行iPhone 7 plus模拟器并将尺寸类别设置为iPhone 7以正常工作。当我在界面生成器中没有改变任何东西的情况下运行iPhone 7的模拟器时,它崩溃了。我意识到视图控制器不适合设备的边缘(模拟或物理),它适合尺寸等级的边缘。我意识到,当我用“.transitioningDelegate = self和.modalPresentationStyle = .custom”评论这些行时,它会像它应该那样工作(但当然没有过渡)。我认为这可能是这个转变的一个问题。你能帮我吗?

这里不用我使用的这个过渡呈现视图控制器的代码片段:

let levelTutorial = CPQuizLevelTutorialViewController() 
levelTutorial.transitioningDelegate = self 
levelTutorial.modalPresentationStyle = .custom 
self.present(levelTutorial, animated: true, completion: nil) 

在这里做了我的代码另一部分,我实现UIViewControllerTransitioningDelegate:

extension CPMainQuizViewController: UIViewControllerTransitioningDelegate { 

    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
     transition.transitionMode = .dismiss 
     transition.startingPoint = self.view.center 
     transition.circleColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha:0.6) 

     return transition 
    } 

    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
     transition.transitionMode = .present 
     transition.startingPoint = self.view.center 
     transition.circleColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha:0.6) 

     return transition 
    } 
} 

Here is a picture of the interface builder. I put a blue background for facilitating the visualization of the problem

Here's what happens

我不知道它是否与错误有关,但我使用xib而不是Storyboard。我确实知道它与bug有关的一点是我对iOS开发很新颖。所以,首先,如果我说了一些愚蠢的话,对不起。 LOL

在此先感谢,伙计们!

嗯,我找到了解决方法。后已经做了,屏幕行为也完全调整其边缘到智能电话边缘

self.view.frame.size = CGSize(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height) 

我加入这行代码在每一个视图控制器我是有这个问题。 :D

我仍然不知道是什么导致了这个错误。所以,如果有人有任何想法,与我们分享。 :D