iOS 8 个自动布局约束因尺寸不同而混乱 类
iOS 8 autolayout constraint messed up in different size classes
我的通用应用程序 (iOS 8) 中有一个名为 'vertical 1' 的视图,在 iPad(wAny hAny) 中,它的高度是 238,在 iPhone portrait(wCompact, hRegular),它的高度由它的顶视图和底视图动态计算。 xib 文件中的代码段如下所示,请注意约束 (id: 05F-Ed-Vem
) 被排除在 heightClass=regular-widthClass=compact
变体中。所有containts在Interface Builder中都没有问题。
<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 约束),仍然在 [=43= 中收到 Unable to simultaneously satisfy constraints.
警告] 模拟器。而 wAny、hAny 中的那些约束在 iPad.
中完美地工作
找到一个有类似问题的 post。
更新:
我发现问题 ONLY 存在于自定义 UITableViewCell
中,甚至只有两个简单的 UIImageView
和 UIView
,在 wAny hAny 中定义并在 wCompact 中卸载的约束hRegular会出现在iPhone模拟器中,出现warning。
好吧,最后我用了两个分开的xib
文件,一个给phone,一个给pad。
至少它有效。
:(
我的通用应用程序 (iOS 8) 中有一个名为 'vertical 1' 的视图,在 iPad(wAny hAny) 中,它的高度是 238,在 iPhone portrait(wCompact, hRegular),它的高度由它的顶视图和底视图动态计算。 xib 文件中的代码段如下所示,请注意约束 (id: 05F-Ed-Vem
) 被排除在 heightClass=regular-widthClass=compact
变体中。所有containts在Interface Builder中都没有问题。
<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 约束),仍然在 [=43= 中收到 Unable to simultaneously satisfy constraints.
警告] 模拟器。而 wAny、hAny 中的那些约束在 iPad.
找到一个有类似问题的 post。
更新:
我发现问题 ONLY 存在于自定义 UITableViewCell
中,甚至只有两个简单的 UIImageView
和 UIView
,在 wAny hAny 中定义并在 wCompact 中卸载的约束hRegular会出现在iPhone模拟器中,出现warning。
好吧,最后我用了两个分开的xib
文件,一个给phone,一个给pad。
至少它有效。
:(