简体   繁体   中英

Animating UIView with Autolayout animates UITableView's checkmark

I have strange behaviour. My whole view controller looks like this (vertical order):

  1. UILabel,
  2. UITableView,
  3. UIView (that will slide in&out when needed). [see ps]

I added constraint between UIView and bottom layout guide and I'm animating it with this method:

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

For some strange reason this screws checkmark, which is now "flying" from outside of left margin of screen and right into correct and expected position, on the right side of selected cell. Belowe I have simple code for selecting/deselecting:

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()
}

Has anybody ever met such weirdness?

ps tried two versions: first, where sliding UIView is hovering in&out on top of tableView, and second where sliding in UIView is shrinking tableView's height. None worked.

Its hard to say, but you might try calling layoutIfNeeded first, then changing the constraint, then calling it again inside the animation block. That gives other layout changes time to update first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM