Swift UIView disappearing from Stack View
Asked Answered
P

3

5

I have a label, an Image View, and a button in a vertical stack view. The alignment is set to fill, and the distribution to equal spacing with an offset of 10. On my storyboard, the label appears on top, the image in center, and the button at bottom.

However, when run on simulator or device, the UIView is stripped from the view entirely, so the label appears at the top of the screen, and the button directly below the label.

My only constraints are set on the stack views to the superview

Image View should be centered between label and button

Edit: Forgot to mention the UIImageView is inside of a UIView

Pancho answered 28/5, 2017 at 20:16 Comment(5)
Does the image view contain an image? If it is empty it might be allocated zero dimensions.Aridatha
Are there any constraints between the image view and its containing UIView?Sailing
There weren't constraints between the two because I overlooked it, but I've pinned the imagview to the uiview now and it still doesn't appear. The image is empty, but is set on tapping the play button. The UIView itself doesn't show either (I'm using it in order to show a static border around the UIImage while the UIImage animates)Pancho
Had to set size constraints on the UIViewPancho
Just for anyone googling here. With Catalyst there are many problems. (As of 2022.) For example, stack views behave weirdly inside table cells. Try moving the app between monitors, and the content of the stack view will often disappear.Metallo
P
0

Setting a Y constraint on the UIView border caused it to appear when hitting the play button, but it grew outside of the screen bounds.

I had to set size constraints on the UIView in order for it to display properly.

Pancho answered 28/5, 2017 at 21:22 Comment(0)
M
5

I had a similar problem. My UIView in my UIStackView had only a Width constraint and would disappear at runtime. I found I could make it show up again with either of these options:

  • Add a Height constraint
  • Add a Top and Bottom constraint
Medardas answered 25/10, 2017 at 22:39 Comment(3)
I had an imageview that I wouldn't set until runtime.. it would always disappear... on the other hand, setting an image at compile time would display the image correctly.Twinge
BTW, only a height or top/bottom constraint didn't solve the problem for me.. in my case I also had to go with a width constraintTwinge
Just add a height constraintImmobilize
K
2

I was having the same issue with a tableview in a stackview. Added the Height constraint to the view and it worked now everything shows fine

Karriekarry answered 5/5, 2019 at 20:24 Comment(0)
P
0

Setting a Y constraint on the UIView border caused it to appear when hitting the play button, but it grew outside of the screen bounds.

I had to set size constraints on the UIView in order for it to display properly.

Pancho answered 28/5, 2017 at 21:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.