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

4

61

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

Garnish answered 17/10, 2015 at 10:50 Comment(3)
please show your code :)Shelbashelbi
there are no code yet. It is a blank project with elements on Main Storyboard. Look at screenshot on the first messageGarnish
This has appeared since using Xcode 7+. I believe other people view this as an "error" from something Apple has done and nothing you have done, but I can't confirm this. I've submitted apps with this and everything seems to be fine.Social
M
158

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.

Mak answered 31/10, 2015 at 17:41 Comment(8)
I set the mode back to Scale To Fill and the warning was gone. Thanks.Pearlene
How did you figure this out? the warning doesn't show any indication of what is causing the problem. But after having this issue, your method solved the problem. I am still curious to know your method of figuring this out.Incompatible
I think that simple's answer better explains the reason of the problemPepper
bruteforce? accident? he is Mr Stacker :DBedpost
Thank you @Lubos Ilcik, it was exactly this problem for me. CheersUnplaced
This is still a thing in 2019 (Xcode 10.2.1)... sighEngelhardt
Thanks, it save me tons of time to figure out the cause.Sanferd
I'm building my UI programmatically and set the content mode to center. Removing that fixes the issue. What a frustrating error message.Prickly
S
75

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.

Steady answered 25/5, 2016 at 21:12 Comment(7)
I think this is by far the most precise answerPepper
Thanks @PepperSteady
Thanks so much. I've been pulling my hair out trying to figure out why a UIView SUBCLASS doesn't react properly to drawRect override and layer manipulations... I think Apple should emphasize this about stack views way more in the docs.Modulation
Glad that I could help @jaga, agree with you on the emphasizing, there is no way to understand that when working with UIStackViews.Steady
@Steady Let's say I'm creating a theme class to change colors globally within an app and I want all my UIViews to have a specified background color, should I do that work on the individual VC in viewDidAppear instead of trying to use UIAppearance?Cassimere
@Cassimere your new question doesn't relate to the topic of this thread. It depends, my opinion is that UIAppearance should be avoided. I recommend using protocols, subclasses or composition to achieve it. Using viewDidAppear is also an option but it defeats the purpose of a global theme class.Steady
@Steady Thank you. I'm getting the exact same error the OP encountered. I commented out the code I was using for UIView and it went away...and my UIViews that were generating the error were inside UIStackViews, though they render the color as desired. Concur re: viewDidAppear. I'm trying to do something that's "one stop shopping" without a bunch of book keeping on the individual VCs. I'll try your suggestion. Thanks again!Cassimere
C
4

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

Cienfuegos answered 8/10, 2018 at 15:17 Comment(0)
A
2

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.

Aviate answered 30/10, 2015 at 17:16 Comment(2)
Well I can see that sometimes it would be nice to have stuff in stack views so you could change the orientation as needed without worrying about constraints and/or having two different classes to handle just two different orientationsWentletrap
I sometimes question myself for the use of StackView over pinning the views. I found that StackView is better choice for several reasons: #1 adding or removing elements will not break anything, #2 client (or designer) keep changing things, colleagues (or future me) won't have to worry about #1 when #2 happensBiosphere

© 2022 - 2024 — McMap. All rights reserved.