如何在循环中对 UIView n 次进行动画处理并跟踪每个动画事件


 UIView.animate(withDuration: 3.0, animations: {
    // UIView.setAnimationRepeatCount(3.0)
        self.leadng.constant = self.view.frame.size.width + self.vwObj.frame.size.width
        self.view.layoutIfNeeded()
    }, completion: { finished in
        UIView.animate(withDuration: 3.0, animations: {
            self.leadng.constant = -(self.vwObj.frame.size.width)
        })
    })

这是我用于对UIView进行动画处理的代码。我正在尝试做的是将UIView动画化n次。这可以使用UIView.setAnimationRepeatCount(3.0(来完成,但问题是我有一个不同的图像数组,我想在UiView中为每个动画显示这些图像。任何知道如何做到这一点的人<</p>

div class="one_answers">

使用 UIImageanimatedImage 属性对图像视图中的多个图像进行动画处理。

ImageView.image = UIImage.animatedImage(with: myImages, duration: 1.0)

其中myImages是要进行动画处理的图像数组。点击此链接了解详情。

编辑:绝对是一种非常粗糙的方法,但它有效。

在班级中宣布了这一点。

let arrayColors = [UIColor.red , UIColor.green, UIColor.blue]
var animationCount = 0

我在viewdidload中调用了animateView((

func animateView() {
    self.vwObj.backgroundColor = arrayColors[animationCount]
    UIView.animate(withDuration: 3.0, animations: {
        self.leadng.constant = self.view.frame.size.width + self.vwObj.frame.size.width
        self.view.layoutIfNeeded()
    }, completion: { finished in
        UIView.animate(withDuration: 3.0, animations: {
            self.leadng.constant =  0
            self.view.layoutIfNeeded()
        }, completion: { finished in
            self.animationCount = self.animationCount + 1
                if self.animationCount < 3 {
                    self.animateView()
                }
        })
    })
}
根据

颜色数组,您可以使用图像数组来设置 imageview.image = arrayImage[animationCount]

似乎

通过以下代码解决了:

UIView.animate(与持续时间: 3.0, 动画: { 打印("动画已开始"( self.leadng.constant = self.view.frame.size.width + self.vwObj.frame.size.width self.view.layoutIfNeed(( print ("BeginCounter --- (self.counter("(

    }, completion: { finished in
        UIView.animate(withDuration: 3.5, animations: {
            self.leadng.constant = -(self.vwObj.frame.size.width)
            print ("AnimationCompleted")
            self.counter = self.counter + 1
            print ("CompleteCounter --- (self.counter)")
            //self.displayAnimation()
            if (self.counter == 3) {
                self.timer?.invalidate()
                self.counter = 0
            }
        })

    })

&calling---- timer = Timer.scheduledTimer(timeInterval: 4.0, target: self, selector: #selector(ViewController.displayAnimation(, userInfo: nil, repeats: true(

最新更新