快速滚动视图不滚动(基于所有约束)?

时间:2019-06-04 23:43:11

标签: swift scrollview

我有一个滚动视图,但没有滚动。而且我会根据约束来设置所有内容。

这就是我添加所有内容的方式:

    self.view.addSubview(scrollView)
    scrollView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor).isActive = true
    scrollView.leadingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leadingAnchor).isActive = true
    scrollView.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.trailingAnchor).isActive = true
    scrollView.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor).isActive = true


    self.scrollView.addSubview(self.collectionView)
    self.scrollView.addSubview(segmentedControl)
    self.scrollView.addSubview(selectThemLabel)
    self.scrollView.addSubview(customButtonLabel)
    self.scrollView.addSubview(numOfButtonsLabel)
    self.scrollView.addSubview(enableMoreButtonLabel)
    self.scrollView.addSubview(BarLabel)
    self.scrollView.addSubview(changeButtonLabelView)
    self.scrollView.addSubview(enableButtonControl)
    self.scrollView.addSubview(dropDownButton)

因此,滚动视图的约束是根据约束设置的,上面我拥有的每个子视图也都使用约束来设置:

{
    super.setConstraints()

    BarLabel.topAnchor.constraint(equalTo: self.scrollView.safeAreaLayoutGuide.topAnchor, constant: 40).isActive = true
    BarLabel.leadingAnchor.constraint(equalTo: self.scrollView.safeAreaLayoutGuide.leadingAnchor, constant: 30).isActive = true
    BarLabel.heightAnchor.constraint(equalToConstant: labelHeight).isActive = true
    BarLabel.widthAnchor.constraint(equalToConstant: labelWidth).isActive = true

    //collectionView
    collectionView.topAnchor.constraint(equalTo: BarLabel.bottomAnchor, constant: 0).isActive = true
    collectionView.leadingAnchor.constraint(equalTo: self.scrollView.leadingAnchor, constant: 0).isActive = true
    collectionView.trailingAnchor.constraint(equalTo: self.scrollView.trailingAnchor, constant: 0).isActive = true
    collectionView.heightAnchor.constraint(equalToConstant: 40).isActive = true

    selectThemLabel.topAnchor.constraint(equalTo: collectionView.bottomAnchor, constant: 60).isActive = true
    selectThemLabel.leadingAnchor.constraint(equalTo: self.scrollView.leadingAnchor, constant: 30).isActive = true
    selectThemLabel.heightAnchor.constraint(equalToConstant: labelHeight).isActive = true
    selectThemLabel.widthAnchor.constraint(equalToConstant: labelWidth).isActive = true

    segmentedControl.topAnchor.constraint(equalTo: selectThemLabel.bottomAnchor, constant: 0).isActive = true
    segmentedControl.leadingAnchor.constraint(equalTo: self.scrollView.leadingAnchor, constant: 20).isActive = true
    segmentedControl.trailingAnchor.constraint(equalTo: self.scrollView.trailingAnchor, constant: -20).isActive = true
    segmentedControl.heightAnchor.constraint(equalToConstant: 40).isActive = true

    customButtonLabel.topAnchor.constraint(equalTo: segmentedControl.bottomAnchor, constant: 60).isActive = true
    customButtonLabel.leadingAnchor.constraint(equalTo: self.scrollView.leadingAnchor, constant: 30).isActive = true
    customButtonLabel.heightAnchor.constraint(equalToConstant: labelHeight).isActive = true
    customButtonLabel.widthAnchor.constraint(equalToConstant: labelWidth).isActive = true

    numOfButtonsLabel.topAnchor.constraint(equalTo: customButtonLabel.bottomAnchor, constant: 0).isActive = true
    numOfButtonsLabel.leadingAnchor.constraint(equalTo: self.scrollView.leadingAnchor, constant: 20).isActive = true
    numOfButtonsLabel.trailingAnchor.constraint(equalTo: self.scrollView.trailingAnchor, constant: -20).isActive = true
    numOfButtonsLabel.heightAnchor.constraint(equalToConstant: 40).isActive = true

    dropDownButton.topAnchor.constraint(equalTo: numOfButtonsLabel.topAnchor, constant: 5).isActive = true
    dropDownButton.widthAnchor.constraint(equalToConstant: 120).isActive = true
    dropDownButton.trailingAnchor.constraint(equalTo: numOfButtonsLabel.trailingAnchor, constant: -10).isActive = true
    dropDownButton.bottomAnchor.constraint(equalTo: numOfButtonsLabel.bottomAnchor, constant: -5).isActive = true

    enableButtonLabel.topAnchor.constraint(equalTo: numOfButtonsLabel.bottomAnchor, constant: 10).isActive = true
    enableButtonLabel.leadingAnchor.constraint(equalTo: self.scrollView.leadingAnchor, constant: 20).isActive = true
    enableButtonLabel.trailingAnchor.constraint(equalTo: self.scrollView.trailingAnchor, constant: -20).isActive = true
    enableButtonLabel.heightAnchor.constraint(equalToConstant: 40).isActive = true

    enableButtonControl.topAnchor.constraint(equalTo: enableButtonLabel.topAnchor, constant: 5).isActive = true
    enableButtonControl.widthAnchor.constraint(equalToConstant: 120).isActive = true
    enableButtonControl.trailingAnchor.constraint(equalTo: enableButtonLabel.trailingAnchor, constant: -10).isActive = true

enableButtonControl.bottomAnchor.constraint(equalTo: enableButtonLabel.bottomAnchor, constant: -5).isActive = true

    changeButtonLabelView.topAnchor.constraint(equalTo: enableButtonLabel.bottomAnchor, constant: 20).isActive = true
    changeButtonLabelView.leadingAnchor.constraint(equalTo: self.scrollView.leadingAnchor, constant: 20).isActive = true
    changeButtonLabelView.trailingAnchor.constraint(equalTo: self.scrollView.trailingAnchor, constant: -20).isActive = true
    changeButtonLabelView.bottomAnchor.constraint(equalTo: self.scrollView.bottomAnchor).isActive = true

    labelTableHeight = changeButtonLabelView.heightAnchor.constraint(equalToConstant: CGFloat(dataSource.count) * inputTableCellHeight)
    labelTableHeight.isActive = true
}

它仍然没有滚动??为什么?

更新

因此它正在滚动(某种),问题是屏幕上的最后一个表格视图被切断,并且当我滚动时,指示器显示我正在向下滚动,但底部表格视图仍在切断...我不知道为什么

0 个答案:

没有答案