就我而言,您可以加注星标并更改停止微光动画吗?

In my case, you can star and change stop shimmer animation?

我有一个这样的例子想在刷新几秒钟后加载微光并完成动画后这样做。 我的代码 starAnimatiom :

func startAnimation() {
        for animateView in getSubViewsForAnimate() {
            animateView.clipsToBounds = true
            let gradientLayer = CAGradientLayer()
            gradientLayer.colors = [UIColor.clear.cgColor, UIColor.white.withAlphaComponent(0.8).cgColor, UIColor.clear.cgColor]
            gradientLayer.startPoint = CGPoint(x: 0.7, y: 1.0)
            gradientLayer.endPoint = CGPoint(x: 0.0, y: 0.8)
            gradientLayer.frame = animateView.bounds
            animateView.layer.mask = gradientLayer

            let animation = CABasicAnimation(keyPath: "transform.translation.x")
            animation.duration = 1.5
            animation.fromValue = -animateView.frame.size.width
            animation.toValue = animateView.frame.size.width
            animation.repeatCount = .infinity

            gradientLayer.add(animation, forKey: "")
        }
    }
    func getSubViewsForAnimate() -> [UIView] {
        var obj: [UIView] = []
        for objView in view.subviewsRecursive() {
            obj.append(objView)
        }
        return obj.filter({ (obj) -> Bool in
            obj.shimmerAnimation

        })
    }

我的代码函数stopAnimation;

@objc func stopAnimation() {
        for animateView in getSubViewsForAnimate() {
            animateView.layer.removeAllAnimations()
            animateView.layer.mask = nil
            timerShimmer.invalidate()
            refresh.endRefreshing()


        }


    }

当我下拉并进行更新时,动画继续运行并且由于某种原因没有运行 stop.What 我做错了吗?

 @objc func obnova() {


        self.startAnimation()
        self.tableView.reloadData()

        self.loadObjects1()
        self.loadObjects2()
        self.loadObjects3()

      // self.refresh.endRefreshing()

    }



override func viewDidLoad() {
        super.viewDidLoad()

 timerShimmer = Timer.init(timeInterval: 0.2, target: self, selector: #selector(stopAnimation), userInfo: nil, repeats: true)
}

请帮帮我?

像下面这样更改最后一部分并尝试

func startTimer() {
    if timerShimmer != nil {
        timerShimmer.invalidate()
        timerShimmer = nil
    }

    timerShimmer = Timer.init(timeInterval: 0.2, target: self, selector: #selector(stopAnimation), userInfo: nil, repeats: true)
}

@objc func obnova() {
    self.startAnimation()
    self.tableView.reloadData()

    self.loadObjects1()
    self.loadObjects2()
    self.loadObjects3()
    startTimer()
}

override func viewDidLoad() {
    super.viewDidLoad()
    startTimer()
}