在横向和纵向之间切换时,IOS AutoLayout具有约束异常 [英] IOS AutoLayout with constraint exception when switching between landscape and portrait

查看:103
本文介绍了在横向和纵向之间切换时,IOS AutoLayout具有约束异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为iPhone 6+的风景和肖像设置了不同的尺寸等级.如果我从横向或纵向开始运行,则不会出现任何约束错误.当我从横向或纵向切换时,我会遇到约束错误.看来,如果我切换,则会同时获得纵向和横向尺寸类别约束的合并.我只设置了1.常规宽度和紧凑高度2.任何宽度和紧凑高度3.紧凑高度和常规宽度4.常规宽度和常规高度.我做错了什么会导致冲突的吗?谢谢.

I have different size classes for iPhone 6+ landscape and portrait. I don't get any constraint error if i run starting from landscape or portrait. The moment i switch from landscape or portrait, i get constraint errors. It seems that if i switch i get a merge of both portrait and landscape's size classes constraint. I have only set up for 1. Regular Width and Compact Height 2. Any Width and Compact Height 3. Compact Height and Regular Width 4. Regular Width and Regular Height. Did i do something wrong that could cause a conflict. Thanks.

推荐答案

如果为Any size类添加约束,则它们将在所有设备上的所有方向应用,因此您需要确保它们与所有其他设备兼容约束.根据您指定的组合(列表中似乎有错字),您似乎经过了过度设计,但很难确定.首先看一下布局引擎删除的约束及其定义的位置,然后您可以找出冲突所在,然后在某些尺寸级别中将其关闭,或重新加工尺寸级别,以使它们完全分开或使用Any案件更加一致.

If you add constraints for the Any size class then they will apply in all orientations on all devices so you need to ensure that they are compatible with all other constraints. Based on the combinations you've specified (there looks to be a typo in your list) it seems like you may have over engineered but it's hard to be sure. Look first at the constraint that's removed by the layout engine and where it's defined then you can find out what the clash is with and turn that one off in some size classes or rework your size classes so that they're all separate or use the Any case more consistently.

这篇关于在横向和纵向之间切换时,IOS AutoLayout具有约束异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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