3

The view hierarchy is simple:

Scroll view (UIScrollView)
    - Content View (UIView)
      - Stack View
         - Hello (UILabel)
         - White view (UIView)

As shown below:

enter image description here

As you see above, the Stack View consists of only two components the Hello (UILabel) and White view (UIView).

What I am encountering is, if I don't embed these two components into a Stack View, running it on device I can see both the "Hello" UIlabel and the white view.

BUT, After I embedded them inside a vertical Stack View, I can only see the "Hello" (UILabel), the white UIView disappear, no matter what constraints I added or removed, no matter how I adjust stack view attribute, it just doesn't show, I always end up with following on device (though everything shows fine on storyboard):

enter image description here

Why?

=== more info ===

In View Hierarchy Debugger of xcode I see Scroll View-->Content View--> Stack View--> the UILabel, I don't see the white view. I don't understand why

Leem.fin
  • 40,781
  • 83
  • 202
  • 354
  • Have you set the white view‘s height? – LinusGeffarth Aug 30 '17 at 19:59
  • @LinusGeffarth, No I didn't, but I use a constraint that makes the white view height equal to the parent view's height, then changed the multiplier to 0.8, in this way the white view height will be proportional to its parent on different devices. I don't want to set constant height, because I want the height to be proportional. – Leem.fin Aug 30 '17 at 20:03
  • Ah I see. What does it show you when debugging the view hierarchy at runtime? Can you see the white view? – LinusGeffarth Aug 30 '17 at 20:04
  • At runtime, I see what I attached the screenshot, I only see the Hello UILabel. But in xcode where I can choose different device screens, it shows fine without issue. Issue comes at runtime in emulator and real device. – Leem.fin Aug 30 '17 at 20:05
  • I was asking what do you see when you [debug the view hierarchy](https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/debugging_with_xcode/chapters/special_debugging_workflows.html)? – LinusGeffarth Aug 30 '17 at 20:07
  • @LinusGeffarth, in view hierarchy debugger, I see Scroll View-->Content View--> Stack View--> the UILabel, I don't see the white view. I don't understand why the white uiview disappear also in hierarchy debugger. – Leem.fin Aug 30 '17 at 20:14
  • Put `print(whiteView)` somewhere. What does it say? – LinusGeffarth Aug 30 '17 at 20:16
  • is the `whiteView` tag name of the view? I mean what is `whiteView` variable? Where should I add it so that xcode knows it refers to the "White View" UIView? (I will be back in 15min) – Leem.fin Aug 30 '17 at 20:20
  • Oh well you need to create a reference to it first. I assumed you’d already done that. (I’ll be back in 8 - hours though, ha, see ya) – LinusGeffarth Aug 30 '17 at 20:22
  • @LinusGeffarth, the `print(whiteView)` prints out `Optional(>)` – Leem.fin Aug 30 '17 at 20:37
  • Actually, in view hierarchy debugger, it shows the white view, but it doesn't show on the graphic view when I rotate the view stack, I don't see the white view. – Leem.fin Aug 30 '17 at 20:51

0 Answers0