首先,我遵循了本教程:https://www.youtube.com/watch?v=B9sH_VxPPo4然后我在我工作的实际项目中使用了这个转换,但从那时起我就遇到了问题。一个我无法理解为什么会发生的问题。也许你可以帮助我。
发生的事情如下:我正在使用此转换为我的应用制作教程。在我为教程设置文本的视图控制器中,我将top,bottom,leading和trailing的约束设置为0.因此,它应该使视图控制器适合边缘,对吧?但它只发生在我在尺寸类中选择了我在模拟器中使用的相同设备时。例如,我必须运行iPhone 7 plus模拟器并将尺寸classe设置为iPhone 7 plus才能正常工作。当我在没有更改界面构建器中的任何内容的情况下运行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
}
}
我不知道它是否有与错误相关的内容,但我使用的是xib而不是Storyboard。有一件事我知道它与这个错误相关的是我对iOS开发很新。所以,首先,抱歉,如果我说了些蠢话。 LOL
先谢谢你,伙计们!
答案 0 :(得分:0)
好吧,我找到了解决方法。
我在每个视图控制器中添加了这行代码,我遇到了这个问题:
self.view.frame.size = CGSize(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
完成后,屏幕会完美地调整其边缘到智能手机边缘。 :d
我仍然不知道导致此错误的原因。所以,如果有人有任何想法,请与我们分享。 :d