添加自定义过渡会导致 xib 加载错误的屏幕尺寸 [英] Adding a custom transition causes xib to load for the wrong screen size
问题描述
我正在尝试向具有 xib 的 UIViewController 添加自定义过渡.我尝试了几种方法,但它们都有相同的问题,视图显示的屏幕尺寸错误.
我当前的示例基于以下教程:
白色的 UIView 设置为居中,宽度为 80%,比例为 1:1.
我的 UIViewController 使用以下内容加载:
让thirdViewController = ThirdViewController()第三视图控制器.transitioningDelegate = viewTransitionDelegate第三视图控制器.modalPresentationStyle = .customnavigationController?.present(thirdViewController,动画:true,完成:nil)
如果我注释掉设置委托,视图将 100% 完美加载:
最后,我有另一个 UIViewController,它没有 xib 并且以编程方式设置约束.此视图加载了相同的过渡并完美加载:
我需要更改什么才能使其与 XIB 一起使用?
我花了很长时间寻找答案,然后从 侧边栏中的相关问题之一.
我需要做的就是将以下内容添加到我的动画师中:
toViewController.view.frame = fromViewController.view.frame
我希望有一天这对某人有所帮助.
I'm trying to add a custom transition to a UIViewController which has a xib. I have tried a few approaches but they all have the same issue, the view displays for the wrong screen size.
My current example is based on the following tutorial: Custom UIViewController transition in iOS with Swift
I have made no changes to the TransitionDelegate or Animators.
Here's the view in the xib and in the simulator:
The white UIView is set to centre, 80% width with a 1:1 ratio.
My UIViewController is loaded using the following:
let thirdViewController = ThirdViewController()
thirdViewController.transitioningDelegate = viewTransitionDelegate
thirdViewController.modalPresentationStyle = .custom
navigationController?.present(thirdViewController, animated: true, completion: nil)
If I comment out setting the delegate the view will load 100% perfectly:
Finally, I have another UIViewController which has no xib and the constraints are set programmatically. This view is loaded with the same transition and loads perfectly:
What do I need to change to get this working with XIBs?
I spent ages looking for an answer to this and then found it from one of the related questions in the sidebar.
All I needed to do was add the following to my animator:
toViewController.view.frame = fromViewController.view.frame
I hope this helps someone one day.
这篇关于添加自定义过渡会导致 xib 加载错误的屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!