Remove white Space after hide views in scrollview?
Asked Answered
C

1

3

I have UIScrollview with dynamic views(Label, Imageview) inside it. I hide some views but white blank space is there. how can I remove it?

I tried with below code but it doesn't work,

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

The layout of File Like:

-View

 -ScrollView

  -UIImageView

  -UIButton

  -UIButton

  -UILable

  -UILable

  -UIButton

  -UILable

  -UILable
Chesterchesterfield answered 2/8, 2017 at 8:5 Comment(6)
can you provide any screenshot ?Glassco
use this layoutsubviews, and change your constraints in this method. If doesnot help then try same in layoutIfNeeded. It will helps you.Indulgence
Do use a view under Scrollview and all your other object in that view.Glassco
@AbhishekMitra Please look at question i have added. all views are inside scrollviewChesterchesterfield
What about using UITableView to achieve what you want? By doing so, you can "hide" views by using a datasource tied to the tableView, and then change the datasource, allowing the tableView to show only what is in the datasource. Afterall, UITableView is a subclass of UIScrollView and gives you a lot of behavior for free to achieve what you want.Tailback
Do Use -View -ScrollView - UIView -UIImageViewGlassco
P
1

Just hiding views won't help, as it still will take place. You have several options: 1. Each of views inside scrollView should have height constraint that should be set to 0 when hiding is required. Then you should call

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

[viewToHide removeFromSuperview];

Pinter answered 2/8, 2017 at 8:29 Comment(1)
Thanks for your answer. if i use [viewToHide removeFromSuperview]; will it remove space @PinterChesterchesterfield

© 2022 - 2024 — McMap. All rights reserved.