简体   繁体   中英

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. The code segament in xib file like below, note that constraint (id: 05F-Ed-Vem ) is exclued in heightClass=regular-widthClass=compact variation. All constaints have no problem in 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

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? 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. warning in iPhone simulator. And those constraints in wAny, hAny work perfectly in 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.

Okay, finally I use two separated xib files, one for phone, one for pad.

At least it works.

:(

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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