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

IosXcodeIos9Xcode7Uistackview

Ios Problem Overview


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?

screenshot

Ios Solutions


Solution 1 - Ios

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

enter image description here

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

Solution 2 - Ios

Any layer change on a UIStackView will result in this warning. As the warning points out UIStackView is a transform-only layer and it differs quite slightly from a UIView. As per documentation:

> 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:.

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 UIStackView behaviour is not the same and should not be confused with UIView.

Solution 3 - Ios

For someone that need: I set clipToBounds to false in StackView.

Solution 4 - Ios

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlex BelkeView Question on Stackoverflow
Solution 1 - IosLubos IlcikView Answer on Stackoverflow
Solution 2 - Iosvictor.vasilicaView Answer on Stackoverflow
Solution 3 - IosRafaela LourençoView Answer on Stackoverflow
Solution 4 - IosRob NorbackView Answer on Stackoverflow