1

I currently have a stack view that is horizontal, fill, fill equally. Inside, there are 3 generic views with different coloured backgrounds.

enter image description here

My current problem is that, when I set one of the views inside to hidden=true, the other two views immediately expands to fill the void. I don't want this. All I want is for the space to remain blank and the target view to be "invisible" both graphically and to UI input events.

enter image description here

AlanSTACK
  • 5,525
  • 3
  • 40
  • 99
  • Possible duplicate of [UIStackView Distribution Fill Equally](https://stackoverflow.com/questions/40254889/uistackview-distribution-fill-equally). It is the same case, but vertical instead of horizontal. – Ahmad F Jan 26 '18 at 08:54

2 Answers2

3

Instead of setting isHidden=true you could set view.alpha = 0 to make it invisible and also view.isUserInteractionEnabled=false to disable UI input events.

*As @robmayoff pointed out below the isUserInteractionEnabled=false is not actually required.

darrenallen7
  • 821
  • 4
  • 9
  • 3
    You don't have to change `isUserInteractionEnabled`. If the view's `alpha` is 0, it automatically ignores touch events. – rob mayoff Jan 26 '18 at 08:52
  • That would be also a workaround (as a trick). You could do it without any cheating :) please check: https://stackoverflow.com/questions/40254889/uistackview-distribution-fill-equally/40256540#40256540 – Ahmad F Jan 26 '18 at 09:07
1

As I can see in your screenshot, you are using the constraints. So, when the element hides, collapses and the other expand.

Use 'opaque' flag to make it invisible.

Vyacheslav
  • 26,359
  • 19
  • 112
  • 194
  • That is not the effect of the `opaque` (in Swift, `isOpaque`) property. – rob mayoff Jan 26 '18 at 08:53
  • That would be also a workaround (as a trick). You could do it without any cheating :) please check: https://stackoverflow.com/questions/40254889/uistackview-distribution-fill-equally/40256540#40256540 – Ahmad F Jan 26 '18 at 09:07