ios 在仅变换层中更改属性 contentsGravity,将不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33185720/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 08:01:58  来源:igfitidea点击:

changing property contentsGravity in transform-only layer, will have no effect

iosxcodeios9xcode7uistackview

提问by Alex Belke

I started to create a very simple tic-tac-toe game. The main goal is to make the view proportional to all screen sizes of all iOS devices. So I put the image on a ViewController, make it full size of screen and then I put it into a Stack View. I've added constrains to this Stack View 0 to all sides. And when I ran the simulator then everything looks good. But I receive a message in console panel. What does it mean?

我开始创建一个非常简单的井字游戏。主要目标是使视图与所有 iOS 设备的所有屏幕尺寸成比例。所以我把图像放在一个ViewController,使它全屏显示,然后我把它放到一个堆栈视图中。我已经向所有方面添加了对此 Stack View 0 的约束。当我运行模拟器时,一切看起来都很好。但是我在控制台面板中收到一条消息。这是什么意思?

screenshot

截屏

回答by Lubos Ilcik

It could happen because you changed the Mode attribute of the StackView:

这可能是因为您更改了 StackView 的 Mode 属性:

enter image description here

在此处输入图片说明

I got this warning when I set Mode to Aspect Fit.

当我将 Mode 设置为 Aspect Fit 时,我收到了这个警告。

回答by victor.vasilica

Any layer change on a UIStackViewwill result in this warning. As the warning points out UIStackViewis a transform-only layerand it differs quite slightly from a UIView. As per documentation:

a 上的任何图层更改UIStackView都将导致此警告。正如警告指出的那样,它UIStackView是一个仅转换层,它与UIView. 根据文档:

The UIStackView is a nonrendering subclass of UIView; that is, it does not provide any user interface of its own. Instead, it just manages the position and size of its arranged views. As a result, some properties (like backgroundColor) have no effect on the stack view. Similarly, you cannot override layerClass, drawRect:, or drawLayer:inContext:.

UIStackView 是 UIView 的非渲染子类;也就是说,它不提供任何自己的用户界面。相反,它只是管理其排列视图的位置和大小。因此,某些属性(如 backgroundColor)对堆栈视图没有影响。同样,您不能覆盖 layerClass、drawRect: 或 drawLayer:inContext:。

More on this here.

更多关于这里

It may not point to the exact source of the OP's issue but hopefully, it will shed some light on why UIStackViewbehaviour is not the same and should not be confused with UIView.

它可能没有指出 OP 问题的确切来源,但希望它能阐明为什么UIStackView行为不一样并且不应该与UIView.

回答by Rafaela Louren?o

For someone that need: I set clipToBoundsto false in StackView.

对于需要的人:我clipToBounds在 StackView 中设置为 false。

回答by Rob Norback

It looks like what you did is perfectly correct.

看起来你所做的完全正确。

However, I'm wondering why you chose to put your imageview into a stackview when you could have just as easily pinned the sides without the stackview. I am a big fan of stackviews but they don't make sense everywhere. Unless you're planning on adding new views, and resizing your ticktactoe board, I might not use it.

但是,我想知道为什么您选择将图像视图放入堆栈视图,而您可以在没有堆栈视图的情况下轻松固定两侧。我是堆栈视图的忠实粉丝,但它们在任何地方都没有意义。除非您打算添加新视图并调整滴答声板的大小,否则我可能不会使用它。