<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                以下主題描述了收集和組織有關布局的信息的技術,以及可能遇到的一些令人驚訝的行為的描述。 不需要在每個布局上使用這些技術,但它們可以幫助您解決最困難的問題。 ## 第一節 理解日志 有關視圖的信息可以打印到控制臺,因為存在不可滿足的布局,或者因為您使用[constraintsAffectingLayoutForAxis:](https://developer.apple.com/documentation/uikit/uiview/1622432-constraintsaffectinglayoutforaxi) 或 [constraintsAffectingLayoutForOrientation:debugging](https://developer.apple.com/documentation/appkit/nsview/1525968-constraintsaffectinglayout) 方法顯式打印了約束。 無論哪種方式,您都可以在這些日志中找到許多有用的信息。 以下是不可滿足的布局錯誤的示例輸出: ~~~ 2015-08-26 14:27:54.790 Auto Layout Cookbook[10040:1906606] 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:0x7a87b000 H:[UILabel:0x7a8724b0'Name'(>=400)]>", "<NSLayoutConstraint:0x7a895e30 UILabel:0x7a8724b0'Name'.leading == UIView:0x7a887ee0.leadingMargin>", "<NSLayoutConstraint:0x7a886d20 H:[UILabel:0x7a8724b0'Name']-(NSSpace(8))-[UITextField:0x7a88cff0]>", "<NSLayoutConstraint:0x7a87b2e0 UITextField:0x7a88cff0.trailing == UIView:0x7a887ee0.trailingMargin>", "<NSLayoutConstraint:0x7ac7c430 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7a887ee0(320)]>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x7a87b000 H:[UILabel:0x7a8724b0'Name'(>=400)]> Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. ~~~ 此錯誤消息顯示五個沖突的約束。 并非所有這些約束都可以同時成立。 您需要刪除一個,或將其轉換為可選約束。 幸運的是,視圖層次結構相對簡單。 您有一個包含標簽和文本字段的父視圖。 沖突的約束設置以下關系: 1. The label’s width is greater than or equal to 400 points. 2. The label’s leading edge is equal to the superview’s leading margin. 3. There is an 8-point space between the label and the text field. 4. The text field’s trailing edge is equal to the superview’s trailing margin. 5. The superview’s width is set to 320 points. 系統嘗試通過破壞標簽的寬度來恢復。 > 注意 > 使用可視格式語言將約束寫入控制臺。 即使您從未使用可視格式語言來創建自己的約束,您也必須能夠閱讀并理解它以有效地調試自動布局問題。 有關更多信息,請參閱[可視格式語言](https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/VisualFormatLanguage.html#//apple_ref/doc/uid/TP40010853-CH27-SW1)。 在這些約束中,最后一個是由系統創建的。 你無法改變它。 此外,它與第一個約束產生明顯的沖突。 如果你的superview只有320點寬,你永遠不會有400點寬的標簽。 幸運的是,您不必擺脫第一個約束。 如果將其優先級降至999,系統仍會嘗試盡可能接近地提供所選寬度,同時仍滿足其他約束。 基于視圖的自動調整遮罩的約束(例如,在 [translatesAutoresizingMaskIntoConstraints](https://developer.apple.com/documentation/uikit/uiview/1622572-translatesautoresizingmaskintoco) 為 YES 時創建的約束)具有有關遮罩的其他信息。 在約束的地址之后,日志字符串顯示h =后跟三個字符,v =后跟三個字符。 A - (連字符)字符表示固定值,而&(和號)表示靈活值。 對于水平遮罩(h =),三個字符表示左邊距,寬邊和右邊距。 對于垂直遮罩(v =),它們表示上邊距,高度和下邊距。 例如,日志消息: ~~~ <NSAutoresizingMaskLayoutConstraint:0x7ff28252e480 h=--& v=--& H:[UIView:0x7ff282617cc0(50)]>" ~~~ 此消息包含以下部分: * NSAutoresizingMaskLayoutConstraint:0x7ff28252e480:約束的類和地址。 在此示例中,該類告訴您它基于視圖的自動調整遮罩。 * h=--& v=—&:視圖的自動調整遮罩。 這是默認遮罩。 水平方向,它具有固定的左邊距,固定的寬度和靈活的右邊距。 它具有固定的上邊距,固定的高度和靈活的下邊距。 換句話說,當superview的大小發生變化時,視圖的左上角和大小保持不變。 * H:[UIView:0x7ff282617cc0(50)]:約束的可視格式語言描述。 在此示例中,它定義了一個具有50個點的恒定寬度的視圖。 此描述還包含受約束影響的任何視圖的類和地址。 ## 第二節 將標識符添加到日志中 雖然前面的示例相對容易理解,但較長的約束列表很快就會變得難以理解。 通過為每個視圖和約束提供有意義的標識符,可以使日志更易于閱讀。 如果視圖具有明顯的文本組件,Xcode將其用作標識符。 例如,Xcode使用標簽的文本,按鈕的標題或文本字段的占位符來標識這些視圖。 否則,在Identity檢查器中設置視圖的Xcode特定標簽。 Interface Builder在其整個界面中使用這些標識符。 其中許多也顯示在控制臺日志中。 對于約束,可以通過編程或使用屬性檢查器來設置它們的標識符屬性。自動布局然后在將信息打印到控制臺時使用這些標識符。 例如,這里有與標識符集合相同的無法滿足的約束錯誤: ~~~ 2015-08-26 14:29:32.870 Auto Layout Cookbook[10208:1918826] 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:0x7b58bac0 'Label Leading' UILabel:0x7b58b040'Name'.leading == UIView:0x7b590790.leadingMargin>", "<NSLayoutConstraint:0x7b56d020 'Label Width' H:[UILabel:0x7b58b040'Name'(>=400)]>", "<NSLayoutConstraint:0x7b58baf0 'Space Between Controls' H:[UILabel:0x7b58b040'Name']-(NSSpace(8))-[UITextField:0x7b589490]>", "<NSLayoutConstraint:0x7b51cb10 'Text Field Trailing' UITextField:0x7b589490.trailing == UIView:0x7b590790.trailingMargin>", "<NSLayoutConstraint:0x7b0758c0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7b590790(320)]>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x7b56d020 'Label Width' H:[UILabel:0x7b58b040'Name'(>=400)]> Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. ~~~ 如您所見,這些標識符允許您快速輕松地識別日志中的約束。 ## 第三節 可視化視圖和約束 Xcode提供的工具可幫助您可視化視圖層次結構中的視圖和約束。 要在模擬器中查看視圖: 1. 在模擬器中運行應用程序。 2. 切換回Xcode。 3. 選擇“Debug > View Debugging > Show Alignment Rectangles”。 此設置概述了視圖的邊緣。 ![](https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/Art/Show_Alignment_Rectangles_2x.png =451x247) 對齊矩形是自動布局使用的邊。 啟用此選項可以快速找到意外調整大小的任何對齊矩形。 如果您需要更多信息,請在Xcode調試欄中單擊Debug View Hierarchy按鈕(![](https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/Art/Screen%20Shot%202015-08-26%20at%2011.35.43%20AM.png) )。然后Xcode顯示一個交互式視圖調試器,為您提供了許多用于探索視圖層次結構并與之交互的工具。 調試自動布局問題時,“顯示剪切的內容(Show clipped content)”和“顯示約束(Show constraints)”選項特別有用。 ![](https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/Art/Debug_View_Hierarchy_2x.png =681x232) 啟用“顯示剪切的內容”選項會顯示可能意外放置在屏幕外的視圖的位置。 啟用“顯示約束”選項會顯示影響當前所選視圖的所有約束。 當事情開始表現奇怪時,這兩個選項都提供了快速的健全性檢查。 有關更多信息,請參閱 [Debug Area Help](http://help.apple.com/xcode)。 ## 第四節 了解邊緣情況 以下是一些可能導致自動布局以意外方式運行的邊緣情況: * 自動布局根據對齊矩形而不是框架來定位視圖。 大多數情況下,這些值是相同的。 但是,某些視圖可能會設置自定義對齊矩形以從布局計算中排除部分視圖(例如,徽章)。 有關更多信息,請參閱 [UIView類參考中](https://developer.apple.com/documentation/uikit/uiview) 的使用自動布局對齊視圖。 * 在 iOS 中,您可以使用視圖的 transform 屬性來調整視圖大小,旋轉或移動視圖; 但是,這些轉換不會以任何方式影響自動布局的計算。 自動布局根據其未轉換的幀計算視圖的對齊矩形。 * 視圖可以顯示其邊界之外的內容。 大多數情況下,視圖行為正常并將其內容限制在其范圍內。 但是,出于性能原因,圖形引擎不強制執行此操作。 這意味著可以以與其幀不同的大小繪制視圖(尤其是具有自定義繪圖的視圖)。 您可以通過將視圖的 [clipsToBounds](https://developer.apple.com/documentation/uikit/uiview/1622415-clipstobounds) 屬性設置為 YES 或通過驗證視圖框架的大小來識別這些錯誤。 * 僅當所有視圖以其內部內容高度顯示時,[NSLayoutAttributeBaseline](https://developer.apple.com/documentation/appkit/nslayoutattribute/nslayoutattributebaseline),[NSLayoutAttributeFirstBaseline](https://developer.apple.com/documentation/appkit/nslayoutattribute/nslayoutattributefirstbaseline) 和 [NSLayoutAttributeLastBaseline](https://developer.apple.com/documentation/appkit/nslayoutconstraint/attribute/lastbaseline) 屬性才能正確對齊文本。 如果其中一個視圖垂直拉伸或收縮,則其文本可能顯示在錯誤的位置。 * 約束優先級在整個視圖層次結構中充當全局屬性。 您通常可以通過在堆棧視圖,布局指南或虛擬視圖中對視圖進行分組來簡化布局; 但是,這種方法并沒有封裝所包含的視圖的優先級。 自動布局繼續將組內的優先級與組外的優先級(甚至是其他組內的優先級)進行比較。 * 寬高比約束允許水平和垂直約束進行交互。 通常,水平和垂直布局是分開計算的。 但是,如果約束視圖相對于寬度的高度,則會在垂直和水平約束之間創建連接:它們現在可以相互影響并發生沖突。 這些交互極大地增加了布局的復雜性,并可能導致布局的不相關部分之間出現意外沖突。 >原文地址 >[Debugging Tricks and Tips](https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/DebuggingTricksandTips.html#//apple_ref/doc/uid/TP40010853-CH21-SW1)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看