簡體   English   中英

iOS-自動版面輪換無法正常運作

[英]iOS - auto layout rotation not working as expected

我有為iPad啟用旋轉功能的應用程序(iPhone版本沒有旋轉功能)。 在我的設計中,在情節提要中,我具有以下層次結構: UIView - UIScrollView - UIView 所有“視圖”均設置為全屏顯示。 第二個UIView類設置為MyView ,這是一個帶有外部xib文件的類。 情節提要和xib均以縱向模式創建。

現在解決問題。

  • 如果我在橫向模式下運行該應用程序,則一切加載正常。 如果此后我旋轉應用程序,一切正常。

  • 如果我以縱向模式運行該應用程序,則設計會“中斷”。 整個內容較薄(因此MyView的末尾與屏幕的末尾之間有大約100+ px的間隙)。 如果我旋轉應用程序,則設計仍然會損壞,但會正確地“放大”。 間隙仍然是相同的大小。 在第一次啟動期間,我在調試器中收到以下錯誤:

     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) ( "<NSAutoresizingMaskLayoutConstraint:0x1545b7800 h=-&- v=-&- UIView:0x1546a8cb0.width == ScrollableContentView:0x154575da0.width - 232>", "<NSLayoutConstraint:0x15458dd80 H:[UIActivityIndicatorView:0x1546afa60]-(370)-| (Names: '|':UIView:0x1546ab840 )>", "<NSLayoutConstraint:0x15458ddd0 H:|-(361)-[UIActivityIndicatorView:0x1546afa60] (Names: '|':UIView:0x1546ab840 )>", "<NSLayoutConstraint:0x1546c7080 H:[UIView:0x1546ab840]-(0)-| (Names: '|':UIView:0x1546a8cb0 )>", "<NSLayoutConstraint:0x1546c7120 H:|-(0)-[UIView:0x1546ab840] (Names: '|':UIView:0x1546a8cb0 )>", "<NSLayoutConstraint:0x154579710 H:|-(0)-[ScrollableContentView:0x154575da0] (Names: '|':UIScrollView:0x15504c000 )>", "<NSLayoutConstraint:0x154686ef0 UIScrollView:0x15504c000.centerX == ScrollableContentView:0x154575da0.centerX>", "<NSLayoutConstraint:0x154697cc0 H:[UIScrollView:0x15504c000]-(0)-| (Names: '|':UIView:0x154547b80 )>", "<NSLayoutConstraint:0x154697d10 H:|-(0)-[UIScrollView:0x15504c000] (Names: '|':UIView:0x154547b80 )>", "<NSLayoutConstraint:0x15463b8c0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x154547b80(768)]>" ) Will attempt to recover by breaking constraint 

無論我做什么,我都無法消除此問題。 即使刪除了幾乎所有約束,我仍然遇到相同的問題。

您應該查看故事板或xib文件中是否沒有任何自動布局警告(文檔輪廓中控制器名稱旁邊的黃色/紅色圓點)。

如果沒有,在添加xib視圖時是否設置約束?

您是否考慮過content hugging prioritycontent compression resistance priority

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM