呈现视图控制器后自动布局无效(以及许多情况) [英] Auto layout invalid after presenting view controller (and many situation)

查看:15
本文介绍了呈现视图控制器后自动布局无效(以及许多情况)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的容器控制器,它就像 UITabBarController,但带有切换动画.我使用自动布局来实现.
因为子控制器之间的切换是动态的,当它的视图添加到容器的视图中时,适当的约束被添加到子视图控制器,而不是在 IB 中预先设置.(约束当然是加到superview的)

I have a custom container controller, which just like UITabBarController, but with switch animation. And I use auto layout to achieve.
Because switch between child controllers is dynamic, the proper constraints are added to child view controller when its's view is added into container's view, not pre-setup in IB. (The constraints are added to the superview of course)

http://d.pr/i/q6NF 容器控制器笔尖设置

附注:约束细节
H:|[Child](将约束的常量改为从左/右到右/左的动画)
H:[子(==超级)]
V:|[孩子]|

PS: The detail of constraints
H:|[Child](Change the constraint's constant to animation from left/right to right/left)
H:[Child(==Super)]
V:|[Child]|

其中一个子控制器是导航控制器,当导航控制器呈现模态视图控制器(使用presentViewController:animated:completion:)时会出错,并关闭它(使用dismissViewControllerAnimated:completion:),导航控制器的framepresent/dismiss后变成(x, y, 0, 0),好像自动布局失效了,可能是约束被去掉了.强>

One of the child controller is a navigation controller, things go wrong when the navigation controller present a modal view controller (using presentViewController:animated:completion:), and dismiss it(usingdismissViewControllerAnimated:completion:), after present/ dismiss the frame of navigation controller become (x, y, 0, 0), It seems like the auto layout becomes invalid, maybe the constraints been removed.

http://d.pr/i/VmvL 出席/解雇流程

我还没有使用代码来验证这些约束会发生什么,但是使用 Spark Inspector,我看到在呈现/解除过程中视图呈现发生了变化.当我的导航控制器呈现一个模态视图控制器时,iOS 只是交换整个导航控制器的视图到模态视图控制器的视图.当导航控制器的视图返回时,自动布局不再起作用.

I haven't use code to verify what happen to these constraints yet, but with Spark Inspector I see the views presentation change during the present/ dismiss process. When My navigation controller present a modal view controller, iOS just swap the whole navigation controller's view to the modal view controller's view. And when navigation controller's view come back, the auto layout doesn't work anymore.

我想出的解决方案之一是让我的容器控制器呈现模态控制器.

One of the solution I came up with is let my container controller present modal controller.

或者我只是将容器控制器更改为不自动布局.

Or I just change my container controller to no auto layout.

事实是自从我开始使用自动布局以来,这种技术引起的问题就占据了优势.除了这个问题,每次界面方向改变时,我的容器控制器内的视图无法自动布局,似乎子视图总是在方向改变之前使用超视图的框架.我仔细检查了我设置的约束,没有冲突也没有歧义.

The fact is ever since I start using auto layout, the problems this technique causes just dominate the benefits. Besides this problem, Every time the interface orientation changes, views inside my container controller just can't auto layout right, it seems subviews always use the frame of superview before orientation change. I double check the constraints I setup, there is no conflicts and no ambiguity.

我的猜测是我的自定义容器控制器与在自动布局系统中呈现模态视图控制器和界面方向更改不兼容,即使设置了约束也是如此.

My guess is that my custom container controller isn't compatible with presenting modal view controller and interface orientation change in Auto Layout system, even with constraints setup.

Xcode 5 beta, iOS 7SDK, target iOS6.1 也许 SDK 环境有问题?

Xcode 5 beta, iOS 7SDK, target iOS6.1 Maybe Something not right with the SDK environment?

推荐答案

我遇到了类似问题.我在我的根 UIView 上设置了 translatesAutoresizingMaskIntoConstraints = NO;.看起来最外层"的 UIView - 层次结构根部的超级视图必须使用默认的 translatesAutoresizingMaskIntoConstraints = YES.一旦我删除了它,一切都按预期工作.

I had a similar problem. I was setting translatesAutoresizingMaskIntoConstraints = NO; on my root UIView. It appears the "outermost" UIView - the superview at the root of your hierarchy must use the default translatesAutoresizingMaskIntoConstraints = YES. Once I've removed this, everything worked as expected.

这篇关于呈现视图控制器后自动布局无效(以及许多情况)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆