首页 文章

使用Autolayout动画UIView动画UITableView的复选标记

提问于
浏览
1

我有奇怪的行为 . 我的整个视图控制器看起来像这样(垂直顺序):

  • UILabel,

  • UITableView,

  • UIView(需要时会滑入和滑出) . [见p.s.]

我在UIView和底部布局指南之间添加了约束,我用这个方法设置了它的动画:

func toggleContinueButton(_ toggleOn: Bool) {
    if toggleOn {
        self.buttonViewConstraint.constant = 0
    } else {
        self.buttonViewConstraint.constant = -80
    }
    UIView.animate(withDuration: 0.5) {
        self.view.layoutIfNeeded()
    }
}

由于一些奇怪的原因,这个螺丝选中标记,现在从屏幕左边缘的外部“飞行”,并且右边进入所选单元格右侧的正确和预期位置 . 下面我有简单的选择/取消选择代码:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.cellForRow(at: indexPath)!.accessoryType = .checkmark
    self.updateContinueButtonState()
}

func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
    tableView.cellForRow(at: indexPath)!.accessoryType = .none
    self.updateContinueButtonState()
}

有没有人见过这样的怪异?

附:我尝试了两个版本:第一,滑动UIView在tableView上面悬停进出,第二个是在UIView中滑动缩小tableView的高度 . 没有用 .

1 回答

  • 0

    很难说,但你可能首先尝试调用 layoutIfNeeded ,然后更改约束,然后在动画块内再次调用它 . 这使得其他布局更改时间首先更新 .

相关问题