Remove white space after hidden views in scrollview?

I have a UIScrollview with dynamic views (Label, Imageview) inside it. I hide some views, but there is empty empty space. how to remove it?

I tried with the code below, but it does not work,

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:myView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:0]]; 

Layout file Like:

 -View -ScrollView -UIImageView -UIButton -UIButton -UILable -UILable -UIButton -UILable -UILable 
+1
ios objective-c iphone
Aug 02 '17 at 8:05
source share
2 answers

Just hiding your eyes will not help, as it will happen anyway. You have several options: 1. Each of the views inside the scrollView should have a height limit that should be set to 0 when hiding is required. Then you have to call

 [scrollView setNeedsLayout]; [scrollView layoutIfNeeded]; 
  1. You can remove unwanted views from scrollView by calling

[viewToHide removeFromSuperview];

0
Aug 02 '17 at 8:29 on
source share

As far as I know. if there is scrollview and you want to hide any view inside it. you need to set Hidden YES and then change the y position of other views.

if the views have the largest part / bottom, then change the scrollview height.

there is no other way ...

0
Aug 12 '17 at 5:43 on
source share



All Articles