ios – Animation of UI View in desk view cell shouldn’t be constant


For some cause, when the cell that is being animated goes off-screen and comes again, the animation pace adjustments. Upon tapping the cell, a brand new view controller is opened. After I returned from the view controller to the preliminary view, the animation stopped altogether.

To this point, I’ve tried to start out the animation in cellForRowAt, however that did not appear to work both.

Hyperlink to video for the issue: https://drive.google.com/file/d/1jt5IM1Ya4gIfzb1ok-NTmS2QTnrSTNoG/view?usp=sharing

Under is the code for willDisplay cell and the features for animating my ui view inside my desk view cell.

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        if let cell = cell as? DirectionSummaryTableViewCell {
            if let isLive = cell.isLive {
                if isLive {
                    cell.animateBusStatusBackground()
                } else {
                    cell.removeAnimation()
                }
            }
        }
    }
func animateBusStatusBackground() {

        UIView.animate(withDuration: 1.0, delay: 0.0, choices: [.repeat, .autoreverse, .curveEaseInOut], animations: { [weak self] in
            if self?.busStatusView.backgroundColor == .crimson {
                self?.busStatusView.backgroundColor = .grey6
            } else {
                self?.busStatusView.backgroundColor = .crimson
            }
        }, completion: nil)
    }
func removeAnimation() {
        self.busStatusView.layer.removeAllAnimations()
        self.layer.removeAllAnimations()
        self.layoutIfNeeded()
    }

How do I repair this in order that the animation is identical on a regular basis?

Leave a Reply