应用的iOS 8 / X code 6自动布局的制约出现后视图 [英] iOS 8 / XCode 6 autolayout constraints applied after view appears

查看:143
本文介绍了应用的iOS 8 / X code 6自动布局的制约出现后视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有正在只是X code 5和iOS 7罚款项目,但是当我最近下载X code 6,我注意到有一些自动布局怪异的行为。

I have a project that was working just fine with XCode 5 and iOS 7, but when I recently downloaded XCode 6, I noticed some weird behavior with autolayout.

我有,只是有一个UIImageView和两个UILabels景色的故事板。这种观点得到使用UiPageViewController加载。所述的UIImageView在视图水平和垂直方向为中心,有约束从图像视图指定两个标签的距离。当有情况下,当故事板和自动版式价值观发生冲突(例如,在故事板,一个标签是图像显示20个像素以上,但在自动版式说,它应该是高于40像素),它使用的是该自动版式值加载视图之前成功应用。因此,当视图获取显示的第一次,一切都在正确的地方。

I have a storyboard with a view that just has a UIImageView and two UILabels. This view gets loaded using a UiPageViewController. The UIImageView is centered horizontally and vertically in the view and there are constraints specifying the distance of the two labels from the image view. When there is a case when the storyboard and autolayout values conflict (for example, in the storyboard, one label is 20 pixels above the image view but the autolayout says it should be 40 pixels above), it used to be that the autolayout value was successfully applied before the view loaded. Thus, when the view gets shown for the first time, everything is in the right place.

现在与iOS 8 / X code 6,我看到该视图负荷,然后事情跳转到其最终位置自动布局。跳转是明显双方在模拟器和真实设备的最终用户,它是真烦人。有没有办法回到旧的行为?据我所知,没有code已经改变导致此问题。

Now with iOS 8 / XCode 6, I'm seeing that the view loads and then things jump to their final autolayout position. This jump is noticeable to the end user both in the simulator and on a real device, and it's really annoying. Is there a way to go back to the old behavior? As far as I'm aware, no code has changed to cause this issue.

推荐答案

哪里是你的code被更改您的约束?

Where is your code that is making changes to your constraints?

如果你保持它的 viewWillAppear中:你有这个问题。我发现的 viewDidLayoutSubviews 行之有效的iOS8上但不一定适用于iOS7倒退。

If you're keeping it in viewWillAppear: you will have that problem. I found that viewDidLayoutSubviews works well for iOS8 but not always for iOS7 backwards.

最后,如果你不能使用 viewDidLayoutSubviews ,有什么我建议是隐藏的 viewDidLoad中的容器视图,并在 viewWillAppear中取消隐藏它,只有后的约束已被应用。加载屏幕,但限制更改获取对用户透明时,它可以让你一个小的额外的延迟。

Eventually, if you cant use viewDidLayoutSubviews, what I'd suggest is hide the container view in viewDidLoad and unhide it in viewWillAppear, only after the constraints have been applied. It gets you a small extra delay when loading the screen but the constraints change gets transparent to the user.

这篇关于应用的iOS 8 / X code 6自动布局的制约出现后视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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