debugging Auto Layout:Logical Errors

Logical Errors逻辑错误

Logical errors are simply bugs. Somewhere, you have an assumption that is faulty. Perhaps it’s an assumption about how Auto Layout calculates the views’ frames. Perhaps it’s an assumption about the set of constraints that you’ve created, or the view properties you’ve set. Perhaps it’s an assumption about how the constraints interact to create complex behaviors. Regardless, something somewhere does not quite match your mental model.

逻辑错误只是错误。某处,你有一个假设是错误的。也许这是关于自动布局如何计算视图框架的假设。也许这是关于你创建的约束集的假设,或者是你设置的视图属性。也许这是一个假设的约束如何相互作用,创造复杂的行为。无论如何,某个地方的东西与你的心智模型不太相符。

Logical errors are the hardest to find. After you eliminate all other possibilities, whatever remains, however improbable, must be a logical error. However, even after you’ve determined that you have a bug, you must still discover where, exactly, the faulty assumption lies.

逻辑错误是最难找到。在排除所有其他可能性之后,无论剩下什么,无论多么不可能,都必须是一个逻辑错误。然而,即使你已经确定你有一个bug,你必须仍然发现哪里,确切地说,错误的假设谎言。

There are no tools or step-by-step instructions here. Fixing logical errors typically involves experiments and iterative tests, both to identify the problem and to figure out how to fix it. There are, however, a few suggestions that may help:

这里没有工具或一步一步的说明。固定逻辑错误通常涉及实验和迭代测试,既要找出问题,又要找出如何解决它。有,但是,一些建议,可能有助于:

  • Review the existing constraints. Make sure you haven’t missed any constraints or accidentally added unwanted constraints. Make sure all the constraints are attached to the correct items and attributes.回顾现有约束。确保您没有错过任何约束或意外添加不必要的约束。确保所有约束都附在正确的项目和属性上。
  • Double-check the view frames. Make sure nothing is getting unexpectedly stretched or shrunk.双检查视图帧。确保没有什么意外的拉伸或缩小。

    This is particularly important for views with invisible backgrounds, like labels or buttons. It may not be obvious when these items are unexpectedly resized.这是特别重要的视图与无形的背景,如标签或按钮。它可能不是很明显时,这些项目都是出人意料的调整。

    One symptom of resizing is that baseline-aligned views no longer line up properly. This is because the baseline alignment works only when the view is displayed at its intrinsic content height. If you stretch or shrink the view vertically, the text mysteriously appears in the wrong location.调整大小的一个症状是基线对齐视图不再正确排列。这是因为基线对齐仅在视图以其内在内容高度显示时生效。如果垂直拉伸或缩小视图,则文本会出现在错误的位置。

  • If a control should always match its intrinsic content size, give it a very high content-hugging and compression-resistance priority (for example, 999).

    如果控件应该始终匹配其内在内容的大小,给它一个非常高的内容拥抱和压缩优先权(例如,999)。

  • Look for any assumptions that you’re making about the layout, and add explicit constraints to make sure those assumptions are true.寻找关于布局的任何假设,并添加显式约束以确保这些假设是正确的。

    Remember, unsatisfiable layouts are generally the easiest problems to find and fix. Add additional constraints until you have a conflict, then examine and fix the conflict.

    记住,不可满足的布局一般是最容易发现问题和解决问题。添加额外的约束,直到你有冲突,然后检查和修复冲突。

  • Try to understand why the given constraints are producing the results that you see. If you understand it, you’re well on the way to fixing it.试着理解为什么给定的约束产生你所看到的结果。如果你明白了,那么你就在修复它的道路上。
  • Experiment with alternative constraints. Auto Layout typically gives you a number of different solutions for the same problem. Trying an different approach may fix the problem or at least make it easier to spot the mistake.替代约束实验。自动布局通常为同一问题提供多个不同的解决方案。尝试不同的方法可以解决这个问题,或者至少能让你更容易发现错误。
时间: 2024-10-13 20:22:27

debugging Auto Layout:Logical Errors的相关文章

debugging Auto Layout:Debugging Tricks and Tips

Debugging Tricks and Tips调试技巧和技巧 The following topics describe techniques for gathering and organizing information about your layout, as well as descriptions of some surprising behaviors you may encounter. You may not need to use these techniques on

Debugging Auto Layout

Types of Errors错误类型 Errors in Auto Layout can be divided into three main categories:自动布局中的错误可分为三大类: Unsatisfiable Layouts. Your layout has no valid solution. For more information, see Unsatisfiable Layouts.永无止境的布局.您的布局没有有效的解决方案.更多信息,见永无止境的布局. Ambiguo

Debugging Auto Layout:Ambiguous Layouts

Ambiguous Layouts 模棱两可的布局 Ambiguous layouts occur when the system of constraints has two or more valid solutions. There are two main causes:当约束系统有两个或多个有效解时,会出现不规则的布局.主要有两个原因: The layout needs additional constraints to uniquely specify the position an

Debugging Auto Layout:Unsatisfiable Layouts

Unsatisfiable Layouts永无止境的布局 Unsatisfiable layouts occur when the system cannot find a valid solution for the current set of constraints. Two or more required constraints conflict, because they cannot all be true at the same time. 永无止境的布局出现系统无法找到制约当前

Auto Layout Guide----(一)-----Understanding Auto Layout

Understanding Auto Layout 理解自动布局 Auto Layout dynamically calculates the size and position of all the views in your view hierarchy, based on constraints placed on those views. For example, you can constrain a button so that it is horizontally centered

iOS Programming Introduction to Auto Layout 自动布局

iOS Programming Introduction to Auto Layout ? 自动布局 A single application that runs natively on both the iPad and the iPhone is called a universal application. 一个原生的能运行在iPad 和iPhone 的应用叫做universal application? Then select the Homepwner target in the pr

iOS 7 - Auto Layout on iOS Versions prior to 6.0

链接地址:http://stackoverflow.com/questions/18735847/ios-7-auto-layout-on-ios-versions-prior-to-6-0 Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required. iOS 7 - Auto Layout on

WWDC2016 Session笔记 – Xcode 8 Auto Layout新特性

来源:一缕殇流化隐半边冰霜(@halfrost) 链接:http://t.cn/Rt7sKBv 目录 1.Incrementally Adopting Auto Layout 2.Design and Runtime Constraints 3.NSGridView 4.Layout Feedback Loop Debugging 一.Incrementally Adopting Auto Layout Incrementally Adopting Auto Layout是什么意思呢?在我们IB

iOS之Xcode8 Auto Layout新特性

目录 1.Incrementally Adopting Auto Layout 2.Design and Runtime Constraints 3.NSGridView 4.Layout Feedback Loop Debugging 一.Incrementally Adopting Auto Layout Incrementally Adopting Auto Layout是什么意思呢?在我们IB里面布局我们的View的时候,我们并不需要一次性就添加好所有的constraints.我们可以一