代码之家  ›  专栏  ›  技术社区  ›  Ibrahim Azhar Armar

更新UIScrollView的高度

  •  0
  • Ibrahim Azhar Armar  · 技术社区  · 6 年前

    我在xib文件中有以下设置

    ScrollView (UIScrollView)
        - ContentView (UIView)
            - ImageSlider (FSPagerView)
            - ClinicName (UILabel)
            - ClinicSlogan (UILabel)
            - LineSeparatorView (UIView)
            - ClinicProfile (UITextView)
            - SectionView (Custom UIView)
            - Doctors View (UICollectionView) - Horizontal Scrolling
    

    约束按以下方式设置

    // ScrollView Constraints
    ScrollView.Top = NavigationView.Bottom
    ScrollView.Leading = SafeArea.Leading
    SafeArea.Trailing = ScrollView.Trailing
    SafeArea.Bottom = ScrollView.Bottom
    
    // ContentView Constraints
    ContentView.Top = SuperView.Top
    ContentView.Leading = SuperView.Leading
    SuperView.Trailing = ContentView.Trailing
    SuperView.Bottom = ContentView.Bottom
    ContentView.Height = SuperView.Height (Priority@250)
    ContentView.Width = SuperView.Width
    

    ContentView中的子视图的所有约束都设置为与SuperView(ContentView)相关

    viewDidLoad() 我正在更新cliniclampose和ClinicProfile的文本值,并更新height常量。这是可行的,但是当我更新滚动视图的高度时它不起作用,下面是我调用的代码 viewDidLoad()

    self.clinicSloganLabelHeightConstraint.constant = estimatedFrameFor(
        text: self.clinicSloganLabel.text!,
        font: self.clinicSloganLabel.font!,
        width: self.clinicSloganLabel.frame.width
    ).height
    self.clinicProfileTextViewHeightConstraint.constant = self.clinicProfileTextView.sizeThatFits(
        CGSize(width: self.clinicProfileTextView.frame.width, height: .infinity)
    ).height
    self.scrollView.contentSize.height = 2000
    

    在UIViewController子类中更新滚动视图的高度时,您能帮助我们朝着正确的方向前进吗?

    谢谢你

    1 回复  |  直到 6 年前
        1
  •  0
  •   Ibrahim Azhar Armar    6 年前

    好的,我在IB中使用Autolayout解决了这个问题,我做的是,最后一个视图我在Content视图中添加了“bottomspace To Container”约束,现在所有的内容都在自动调整。