是什么固有大小的系统VS宽度/高度限制的区别? [英] What is the difference of intrinsic size vs system width/height constraints?

查看:200
本文介绍了是什么固有大小的系统VS宽度/高度限制的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开始从泉水和结构布局移动到自动布局和有关于固有大小设置的一些问题。

Starting to move from springs and structs layout to auto layout and have some questions regarding "Intrinsic Size" setting.

如果您设置的一些看法固有大小为占位符,并把一些宽度和高度值,则认为不会扩大,将保持固定的大小。但是,如果我们将固有大小到默认(定义系统),那么系统将决定和规模如果在运行期间所需的视图。

If you set "Intrinsic Size" of some view to "Placeholder" and put some width and height values then the view will not scale and will stay of the fixed size. But if we set "Intrinsic Size" to "Default (System defined)" then the system will decide and scale the view if needed during runtime.

不过,我们可以明确设置宽度和高度系统约束通过使用Ctrl +拖动视图。在这种情况下,会有系统的宽度和高度的限制和const占位符值。我检讨现行code,并试图了解它是一个bug,冗余系统的宽度和高度的限制应移走或有一些其他隐藏的逻辑。然而,X code不运行时显示在控制台的警告等。这里的演示项目的打印屏幕:

However, we could explicitly set width and height system constraints to the view by using Ctrl + Drag. In such case there would be system width and height constraints AND const placeholder values. I'm reviewing existing code and trying to understand is it a bug and redundant system width and height constraints should be removed OR there's some other hidden logic. However, Xcode does not show any warnings and etc in console during runtime. Here's a print screen of demo project:

推荐答案

当您设置的固有大小为占位符,你告诉X code的布局,你的看法就会有大小依赖于它的内容系统(如一个标签可以是依赖于它的文本内容)。该系统只知道,并保持与固有大小欣赏到自己的类型。如果你想有一个属于自己的看法类似的经历,考虑视图,如果它有一个内在的大小。然后,您设置的限制,如果认为应该生长或根据其内容的萎缩。最后,实施 intrinsicContentSize 方法计算并返回内容的正确大小。如果内容的变化和新的计算应该执行,你叫 invalidateIntrinsicContentSize 你的看法。根据您如何设置的限制,你的看法要么成长和/或缩小,或将是静态的(像你可以设置宽度和高度的标签上的限制,它仍然是静态的)。

When you set the intrinsic size to "Placeholder", you tell the Xcode layout system that your view will have size dependent on its content (like a label can be dependent on its text content). The system only knows and maintains its own types of views with intrinsic size. If you wish to have a similar experience with a view of your own, to consider the view as if it has an intrinsic size. Then you set up your constraints as if the view should grown or shrink depending on its content. Finally, you implement the intrinsicContentSize method to calculate and return the correct size of the content. If the content changes and a new calculation should be performed, you call invalidateIntrinsicContentSize on your view. Depending on how you have set up your constraints, your view will either grow and/or shrink, or it will be static (like you can set a width and height constrains on a label, and it remains static).

这篇关于是什么固有大小的系统VS宽度/高度限制的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆