简体   繁体   English

iOS 8自动布局约束陷入了不同大小的类中

[英]iOS 8 autolayout constraint messed up in different size classes

I have a view named 'vertical 1' in my universal app (iOS 8), in iPad(wAny hAny), its height is 238, and in iPhone portrait(wCompact, hRegular), its height is dynamically caculated by its top and bottom view. 我在通用应用程序(iOS 8),iPad(wAny hAny),高度为238和iPhone portrait(wCompact,hRegular)中有一个名为“垂直1”的视图,其高度由顶部和底部动态计算视图。 The code segament in xib file like below, note that constraint (id: 05F-Ed-Vem ) is exclued in heightClass=regular-widthClass=compact variation. xib文件中的代码段如下所示,请注意,在heightClass=regular-widthClass=compact变体中heightClass=regular-widthClass=compact了约束(id: 05F-Ed-Vem )。 All constaints have no problem in Interface Builder. 所有内容在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>

But when I run app in iPhone 5s simulator which is wCompact hRegular size, I got console warning like below 但是当我在wCompact hRegular尺寸的iPhone 5s模拟器中运行应用程序时,出现如下控制台警告

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)]>

which is very very weird, because height 238 should not be presented in iPhone layout right? 这是非常非常奇怪的,因为不应该在iPhone布局中显示高度238吗? Does anyone know why? 有人知道为什么吗? Thank you in advance. 先感谢您。

Update: 更新:
I have tried to clear all my constraints in wCompact, hRegular size (in the other word, no ANY constraints in this size), still got Unable to simultaneously satisfy constraints. 我试图清除wCompact,hRegular大小中的所有约束(换句话说,此大小中没有任何约束),但仍然Unable to simultaneously satisfy constraints. warning in iPhone simulator. iPhone模拟器中发出警告。 And those constraints in wAny, hAny work perfectly in iPad. 而且,在所有这些限制条件下,任何人都可以在iPad上完美运行。

Found a post which has a similar problem. 找到了具有类似问题的帖子

Update: 更新:
I found the problem ONLY exists in custom UITableViewCell , even only has two simple UIImageView and UIView , contraints defined in wAny hAny and uninstalled in wCompact hRegular will be presented in iPhone simulator, and the warning occurs. 我发现这个问题存在于自定义UITableViewCell ,即使只有两个简单UIImageViewUIView ,在温妮HANY定义和卸载在wCompact hRegular约束上会在iPhone模拟器呈现,并出现警告。

Okay, finally I use two separated xib files, one for phone, one for pad. 好的,最后我使用了两个分开的xib文件,一个用于电话,一个用于键盘。

At least it works. 至少有效。

:( :(

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM