码迷,mamicode.com
首页 > 其他好文 > 详细

Autolayout 03

时间:2014-12-25 17:52:51      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

Debugging in Code

有两个调试layout问题的阶段。

1. Map from “this view is in the wrong place” to “this constraint (or these constraints) is (are) incorrect.”

2. Map from “this constraint is incorrect” to “this code is incorrect.”

To debug a problem with Auto Layout

 

  1. Identify the view with an incorrect frame.
    It may be obvious which view has the problem; if it is not, you may find it helpful to use the NSView

    method _subtreeDescription to create a textual description of the view hierarchy.

  2. If possible, reproduce the issue while running under the Auto Layout template in Instruments.

  3. Find the bad constraint or constraints.

    To get the constraints affecting a particular view, use constraintsAffectingLayoutForOrientation: in OS X or constraintsAffectingLayoutForAxis: in iOS.

    4.If it’s not obvious which constraint is wrong at this point, visualize the constraints on screen by passing the constraints to the window using visualizeConstraints:.

    When you click a constraint, it is printed in the console. In this way you can you can determine which is which, and typically identify which is incorrect.

 

    At this point you may be informed that the layout is ambiguous.

  5. Find the code that’s wrong.
    Sometimes, once you have identified the incorrect constraint, you will know what to do to fix it.

    If this is not the case, then use Instruments to search for the pointer of the constraint (or some of its description). This will show you interesting events in that constraint’s lifecycle—its creation, modification, installation into windows, and so on. For each of these you can see the backtrace where it happened. Find the stage at which things went awry, and look at the backtrace. This is the code with the problem.

 

Auto Layout by Example

Auto Layout 使得自动解决复杂的layout问题很容易。而且不需要手动的操作。通过创建正确的约束,你可以创建在代码中难以掌控的layout。例如同等空间的view调整适应方向或者大小的变动。scroll view中作用于滚动内容大小的元素。或者scroll view中不滚动的元素。

Using Scroll Views with Auto Layout

当你在app中使用auto layout时,scroll view将会是一个挑战。滚动内容大小必须设置正确用户才能够滚动到可视区域。例如,如果你需要为了地图缩放和说明在scroll view的顶部设定一个contextual view,是很难确定这些元素不会跟着其他的content一起滚动。

Controlling Scroll View Content Size

 

 

 

 

Autolayout 03

标签:

原文地址:http://www.cnblogs.com/lisa090818/p/4185037.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!