0

I am developing small IOS application in which I am using scrollview with auto layout.Everything is working fine.But only thing when I hide any of the view inside the scrollview it is not adjusting scrollview height according to that. My view hierarchy looks like

Scrollview -> View -> view1
                   -> view2
                   -> view3
                   -> view4

So in above situation if I hide view3 then it is not adjusting layout.It left empty place in place of hide view. Am I doing something wrong? How to use auto layout and scrollview with dynamic height?

esqew
  • 42,425
  • 27
  • 92
  • 132
nilkash
  • 7,408
  • 32
  • 99
  • 176

3 Answers3

0

Hiding a view does not remove it from the view hierarchy, only makes it invisible.

If you want to do this with autolayout, you need to remove the view from the hierarchy (removeFromSuperview) and then adjust the various constraints as needed. This generally means you will need to maintain a reference to all constraints that will need to change.

Andrew Monshizadeh
  • 1,784
  • 11
  • 16
  • Hi @Andrew thank you for quick answer. Do you have Any example for it? – nilkash Dec 25 '14 at 04:49
  • Sorry, I'm traveling and on mobile right now. But, here is a question I answered previously that essentially does the opposite (add views and make the superview grow using autolayout) and should give you a good idea how to proceed. http://stackoverflow.com/questions/27317228/resize-superview-while-adding-subviews-dynamically-with-autolayout/27334720#27334720 – Andrew Monshizadeh Dec 25 '14 at 06:19
  • Hye no worries sir. Thank you for your kind help.Will check your solution – nilkash Dec 25 '14 at 07:22
0

you should use UITableView and use deleteRowsAtIndexPaths to remove view

Dai
  • 36
  • 1
  • 2
  • my UI is much complex mean it contains table as well as collection view inside it. So using table view and inside that again table view and collection view will become much complex to handle. Is there any other solution ? – nilkash Dec 25 '14 at 05:00
0

You should change its width and height to 0. Animating this property results in a graceful decrement in the scrollview's content view. Make sure to properly set the autolayout for the subviews.

Abhishek Kumar
  • 324
  • 2
  • 8