[英]iOS 8 autolayout constraint messed up in different size classes
我在通用應用程序(iOS 8),iPad(wAny hAny),高度為238和iPhone portrait(wCompact,hRegular)中有一個名為“垂直1”的視圖,其高度由頂部和底部動態計算視圖。 xib文件中的代碼段如下所示,請注意,在heightClass=regular-widthClass=compact
變體中heightClass=regular-widthClass=compact
了約束(id: 05F-Ed-Vem
)。 所有內容在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>
但是當我在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)]>
這是非常非常奇怪的,因為不應該在iPhone布局中顯示高度238嗎? 有人知道為什么嗎? 先感謝您。
更新:
我試圖清除wCompact,hRegular大小中的所有約束(換句話說,此大小中沒有任何約束),但仍然Unable to simultaneously satisfy constraints.
iPhone模擬器中發出警告。 而且,在所有這些限制條件下,任何人都可以在iPad上完美運行。
找到了具有類似問題的帖子 。
更新:
我發現這個問題只存在於自定義UITableViewCell
,即使只有兩個簡單UIImageView
和UIView
,在溫妮HANY定義和卸載在wCompact hRegular約束上會在iPhone模擬器呈現,並出現警告。
好的,最后我使用了兩個分開的xib
文件,一個用於電話,一個用於鍵盤。
至少有效。
:(
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.