问题描述
我正在迁移使用 NIB 的旧代码以使用手动视图创建 (loadView
) 和 自动布局.根视图控制器是一个容器 VC(有 2 个子级),它使用自动布局并以模态方式呈现一个视图控制器,其布局在 NIB 中指定,但尚未使用自动布局.presentViewController:animated:completion:
之后一切都很好,但是当模态视图通过委托调用以 dismissViewControllerAnimated:completion:
关闭时,呈现视图会变得奇怪,内容被奇怪地移动并且对触摸没有反应的不可用状态.
I'm migrating older code that used NIBs to use manual view creation (loadView
) and Auto Layout. The root view controller is a container VC (with 2 children) that uses auto layout and modally presents a view controller that has its layout specified in a NIB and does not yet use auto layout. All is fine after presentViewController:animated:completion:
, but when the modal view is closed with dismissViewControllerAnimated:completion:
via delegate call, the presenting view is left in a strange, unusable state where the content is weirdly shifted and does not react to touch.
我已尝试创建最小的测试用例来重现该问题,但我未能重现该问题.
I have tried to create minimal test case to reproduce the problem, but I've failed to reproduce the issue.
这可能是什么原因造成的?
What could be causing this?
推荐答案
我在我的根 UIView
上设置了 translatesAutoresizingMaskIntoConstraints = NO;
.它似乎是最外层"的 UIView
— 位于视图层次结构根部的超级视图必须使用默认的 translatesAutoresizingMaskIntoConstraints = YES
.一旦我删除了它,一切都按预期工作.
I was setting translatesAutoresizingMaskIntoConstraints = NO;
on my root UIView
.It appears the "outermost" UIView
— the superview at the root of your view hierarchy must use the default translatesAutoresizingMaskIntoConstraints = YES
.Once I've removed this, everything worked as expected.
这篇关于在dismissViewControllerAnimated 后查看不可用:完成:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!