ScrollView滚动到约束之外

问题描述 投票:0回答:1

我内部有一个UIScrollView和一个UIStackView。我的问题是,滚动时,内容滚动超出了其约束。为什么会这样呢?我是否需要设置其他constraints

enter image description here enter image description here

这些是我的constraints

view.addSubview(theScrollView)
theScrollView.addSubview(theStackView)

    theScrollView.topAnchor.constraint(equalTo: theLabel.bottomAnchor, constant: 20).isActive = true
    theScrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 30).isActive = true
    theScrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -30).isActive = true
    theScrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true

    theStackView.topAnchor.constraint(equalTo: theScrollView.topAnchor).isActive = true
    theStackView.leadingAnchor.constraint(equalTo: theScrollView.leadingAnchor).isActive = true
    theStackView.trailingAnchor.constraint(equalTo: theScrollView.trailingAnchor).isActive = true
    theStackView.bottomAnchor.constraint(equalTo: theScrollView.bottomAnchor).isActive = true
    theStackView.widthAnchor.constraint(equalTo: theScrollView.widthAnchor).isActive = true

theLabel是顶部的“ Konto erstellen”。知道我如何适应吗?

如果有任何不清楚的地方,请告诉我。

ios swift uiscrollview constraints uistackview
1个回答
0
投票

在您的SignUpViewController类中...

  • 您将theScrollView添加到view
  • 您将theStackView添加到theScrollView
  • 您将视图添加到theStackView
    • theStackView.addArrangedSubview(emailView)
    • theStackView.addArrangedSubview(anzeigeNameView)
    • theStackView.addArrangedSubview(usernameView)
    • 使用

但是然后将其他视图添加到view

  • view.addSubview(emailTextField)
  • view.addSubview(anzeigeNameTextField)
  • view.addSubview(usernameTextField)

然后,您将这些视图限制为theStackView中的视图。滚动内容时,这些视图随堆栈视图的子视图一起移动,但是它们是滚动视图的层次结构的[[outside相反,您需要这样做:

view.addSubview(theScrollView) theScrollView.addSubview(theStackView) theStackView.addArrangedSubview(emailView) emailView.addSubview(emailTextField) //view.addSubview(emailTextField) theStackView.addArrangedSubview(anzeigeNameView) anzeigeNameView.addSubview(anzeigeNameTextField) //view.addSubview(anzeigeNameTextField) theStackView.addArrangedSubview(usernameView) usernameView.addSubview(usernameTextField) //view.addSubview(usernameTextField)

现在您的文本字段将是它们各自视图的子视图,它们是堆栈视图的排列子视图。

执行此操作后,您可能需要调整约束。

© www.soinside.com 2019 - 2024. All rights reserved.