ios – Animation of UI View in desk view cell just isn’t constant

[ad_1]

For some motive, when the cell that is being animated goes off-screen and comes again, the animation velocity modifications. 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 date, I’ve tried to begin 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

Beneath is the code for willDisplay cell and the capabilities 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 == .purple {
                self?.busStatusView.backgroundColor = .grey6
            } else {
                self?.busStatusView.backgroundColor = .purple
            }
        }, completion: nil)
    }
func removeAnimation() {
        self.busStatusView.layer.removeAllAnimations()
        self.layer.removeAllAnimations()
        self.layoutIfNeeded()
    }

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

[ad_2]

Leave a Reply