在scrollview中隐藏视图后删除空格? [英] Remove white Space after hide views in scrollview?

查看:119
本文介绍了在scrollview中隐藏视图后删除空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 UIScrollview ,里面有动态视图(Label,Imageview)。我隐藏了一些视图,但是有白色的空白区域。如何删除它?



我尝试使用以下代码,但它不起作用,

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

文件的布局:

  -View 

-ScrollView

-UIImageView

-UIButton

- UIButton

-UILable

-UILable

-UIButton

-UILable

- UILable


解决方案

只是躲在意见不会帮助,因为它还是会发生的。你有几个选择:
1. scrollView中的每个视图都应该有高度约束,当需要隐藏时应该设置为0。然后你应该打电话

  [scrollView setNeedsLayout]; 
[scrollView layoutIfNeeded];




  1. 您可以通过调用从scrollView中删除不需要的视图



  2. [viewToHide removeFromSuperview];


    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
    

    解决方案

    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];

    这篇关于在scrollview中隐藏视图后删除空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆