为什么在大小类不应该安装的约束上出现自动布局错误? [英] Why do I get an autolayout error on a constraint that should not be installed for the size class?

查看:40
本文介绍了为什么在大小类不应该安装的约束上出现自动布局错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iOS8.笔尖已启用自动布局和尺寸类别.我在IB中制作了两种布局,一种布局用于任何宽度/任何高度,一种布局用于任何宽度/紧凑高度.我已经在IB中测试了不同的方向和设备尺寸,并且在IB中没有约束问题.

I'm using iOS 8. My nib has autolayout and size classes enabled. I've made two layouts in IB, one for Any Width/Any Height, and one for Any Width/Compact Height. I've tested different orientations and device sizes in IB and I don't have constraint problems in IB.

现在,当我在手机上运行该应用程序时.该视图以纵向正确布置.然后,我将手机旋转到横向,并得到无法同时满足约束条件".错误.当我查看冲突约束的列表时,我会看到应该为景观布局卸载的约束.旋转完成后,景观布局将正确显示.

Now when I run the app on my phone. The view lays out correctly in portrait. Then I rotate my phone into landscape and I get a "Unable to simultaneously satisfy constraints." error. When I look at the list of conflicting constraints, I see a constraint that should have been uninstalled for landscape layouts. When rotation completes the landscape layout appears correctly.

这似乎是iOS尝试在卸载旧约束之前用新边界对视图进行布局.这是iOS的已知问题吗?我需要执行一个步骤来正确支持尺寸等级吗?

It's as if iOS is trying to lay out the view with the new bounds before the old constraints are uninstalled. Is this a known problem with iOS? Is there a step I need to implement to correctly support size classes?

推荐答案

我仍然认为这是一个iOS错误,但是我没有时间制作示例项目来重现它.我认为这种布局的不寻常之处在于,当手机旋转到横向时,我的图像视图会移动到完全不同的位置.

I still think this is an iOS bug, but I don't have time to make a sample project to reproduce it. I think what is unusual about this layout is that I have an image view that moves to an entirely different location when the phone is rotated into landscape.

图像尺寸上的宽度约束对于这两个尺寸类别都有不同的常数,但这会引发异常.

The width constraint on the image view had different constants for either size class, but this was throwing an exception.

接下来要尝试的是使用不同的宽度约束.一个安装为紧凑的高度,另一个安装为其他所有.即使不应该安装破坏约束,这仍然会引发异常.

The next thing tried was to use different width constraints. One was installed for compact height, the other was installed for everything else. This was still throwing an exception, even though the breaking constraint should not have been installed.

最后,我要解决的问题是拥有两个图像视图,一个用于常规布局,一个用于紧凑的高度.一次仅安装一个图像视图.这毫无例外,并且看起来完全一样.

Finally, the solution I got working was to have two image views, one for regular layouts, and one for compact height. Only one image view was installed at a time. This works without exceptions and looks exactly the same.

这篇关于为什么在大小类不应该安装的约束上出现自动布局错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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