iOS 8自动布局约束在不同大小的类中搞砸了

时间:2015-06-29 18:33:31

标签: ios ios8 autolayout

我的通用应用程序(iOS 8)中有一个名为“vertical 1”的视图,在iPad(wAny hAny)中,它的高度为238,在iPhone纵向(wCompact,hRegular)中,其高度由其动态计算顶视图和底视图。 xib文件中的代码段如下所示,请注意约束(id:05F-Ed-Vem)在heightClass=regular-widthClass=compact变体中被排除。所有constaints在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 size时,我得到了如下控制台警告

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有类似问题。

更新:
我发现问题存在于自定义UITableViewCell中,即使只有两个简单的UIImageViewUIView,在wAny hAny中定义并在wCompact hRegular中卸载的约束将是在iPhone模拟器中显示,并发出警告。

1 个答案:

答案 0 :(得分:1)

好的,最后我使用了两个单独的xib个文件,一个用于手机,一个用于打击垫。

至少它有效。

:(