Макет сломан, когда я обновляю ограничение высоты табличного представления программно - PullRequest
0 голосов
/ 08 апреля 2020

, когда я пытаюсь обновить константу ограничения высоты представления таблицы, это вызывает ошибку в представлении. Что я делаю не так?


  func setupViewHeight() {
    // prepare the animator first and keep a reference to it
    let animator = UIViewPropertyAnimator(duration: 0.5, timingParameters: UICubicTimingParameters(animationCurve: .linear))
    animator.addAnimations {
        self.view.layoutIfNeeded()
    }

    // at some other point in time we change the constraints and call the animator
    self.tableHeightConstraint.constant = CGFloat(self.previousClinics.count) * self.cellHeight

    self.view.setNeedsLayout()
    animator.startAnimation()

    self.tableView.reloadData()
  }

Оболочка Просмотр ограничений Subview

Оболочка Просмотр ограничений

Багги Посмотреть в действии (видео)

1 Ответ

0 голосов
/ 08 апреля 2020

Вы можете попробовать одну вещь -> изменить приоритет ограничения высоты просмотра таблицы на 100 и попытаться удалить всю фиксированную высоту ячейки. Надеюсь, это поможет вам.

Попробуйте это. Это прекрасно для меня.

let cellHeight = 100.0
var cell : tableCell?
let detailArr : [UIColor] = [.red,.yellow,.black,.blue]

override func viewWillAppear(_ animated: Bool) {
    self.changeTableHeight()
}

func changeTableHeight()
{
    let animator = UIViewPropertyAnimator(duration: 0.5, timingParameters: UICubicTimingParameters(animationCurve: .linear))
    animator.addAnimations {
        self.view.layoutIfNeeded()
    }
    tableviewHeight.constant = CGFloat(Double(detailArr.count) * self.cellHeight)

    self.view.setNeedsLayout()
    animator.startAnimation()

    self.tableview.reloadData()
}

Cell image with constraint

Table view with fix height

Table with orange background color and height as per total number of cell

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...