【发布时间】:2015-09-16 08:22:29
【问题描述】:
我的通用应用程序(iOS 8)中有一个名为“vertical 1”的视图,在 iPad(wAny hAny)中,它的高度是 238,在 iPhone 纵向(wCompact,hRegular)中,它的高度是由它动态计算的顶视图和底视图。 xib 文件中的代码段如下所示,注意约束(id:05F-Ed-Vem)在heightClass=regular-widthClass=compact 变体中被排除。 Interface Builder中所有的containts都没有问题。
<view contentMode="scaleToFill" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="BjW-gW-lfX" userLabel="vertical 1">
<rect key="frame" x="501" y="20" width="1" height="238"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" constant="238" id="05F-Ed-Vem"/>
<constraint firstAttribute="width" constant="1" id="ETL-HL-PI1"/>
<constraint firstAttribute="width" constant="1" id="iNR-DD-mpQ"/>
</constraints>
<variation key="default">
<mask key="constraints">
<exclude reference="ETL-HL-PI1"/>
</mask>
</variation>
<variation key="heightClass=regular-widthClass=compact">
<mask key="constraints">
<exclude reference="05F-Ed-Vem"/>
<include reference="ETL-HL-PI1"/>
<exclude reference="iNR-DD-mpQ"/>
</mask>
</variation>
</view>
但是当我在 iPhone 5s 模拟器中运行 wCompact hRegular 大小的应用程序时,我收到如下控制台警告
Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7fa6327ca1f0 V:[UIView:0x7fa6327c9e70(238)]>",
"<NSLayoutConstraint:0x7fa6327d1510 V:[UIView:0x7fa6327d2ca0(250)]>",
"<NSLayoutConstraint:0x7fa6327dcea0 V:[UIView:0x7fa6327d2ca0]-(16)-[UIView:0x7fa6327dc2e0]>",
"<NSLayoutConstraint:0x7fa6327dddf0 V:[UIView:0x7fa6327c9e70]-(19)-[UIView:0x7fa6327dc2e0]>",
"<NSLayoutConstraint:0x7fa6327dc760 V:[UIView:0x7fa6327cbb60]-(8)-[UIView:0x7fa6327d2ca0]>",
"<NSLayoutConstraint:0x7fa6327dea90 V:[UIView:0x7fa6327cbb60]-(15)-[UIView:0x7fa6327c9e70]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fa6327d1510 V:[UIView:0x7fa6327d2ca0(250)]>
这很奇怪,因为高度 238 不应该出现在 iPhone 布局中,对吧?有谁知道为什么?提前谢谢你。
更新:
我试图清除 wCompact 中的所有约束,hRegular 大小(换句话说,这个大小没有 ANY 约束),仍然在 iPhone 模拟器中收到 Unable to simultaneously satisfy constraints. 警告。 wAny、hAny 中的这些限制在 iPad 中完美运行。
找到一个post也有类似问题。
更新:
我发现问题ONLY存在于自定义UITableViewCell,甚至只有两个简单的UIImageView和UIView,在wAny hAny中定义并在wCompact hRegular中卸载的约束将在iPhone模拟器中呈现,并且警告发生。
【问题讨论】:
-
当您更改尺寸等级时,请务必清除约束,然后再次放置约束
-
紧凑宽度/常规高度正好是
"For all iPhones in portrait"。您甚至声明“这是 wCompact hRegular 大小” - 正是 xml 中指定的大小类。
标签: ios ios8 autolayout