xcode10-循环淡入淡出动画-与完成处理程序同步的代码

时间:2019-06-09 09:19:39

标签: xcode animation

此代码始终运行,并且不等待UI中完成的动画。它应该以三种颜色依次显示淡入​​和淡出视图。我将淡入淡出功能放入了UIView的扩展中。

CV_LOAD_IMAGE_ANYDEPTH

这是我的淡出扩展名:

import UIKit

class ViewController: UIViewController {
let colorArray = [UIColor.red, UIColor.yellow, UIColor.green]
@IBOutlet weak var fadedView: UIView!

override func viewDidLoad() {
    super.viewDidLoad()
   fadedView.backgroundColor = UIColor.brown
    for color in 0..<colorArray.count {
       fadedView.backgroundColor = colorArray[color]
        fadedView.bxFadeIn()
        fadedView.bxFadeOut()
        //UI does not reflect code and shows green background color fade in/out
        print("Fades w/ \(color) done")
    }
}    
}

输出显示循环在动画之前完成。

    func bxFadeIn(){
        if self.alpha == 0{
               UIViewPropertyAnimator.runningPropertyAnimator(withDuration: 1.0,
                                                           delay: 0,
                                                           options: .curveLinear,
                                                           animations: {self.alpha = 1},
                                                           completion: {finished in print("animation finished \(finished)")}
            )
        }
    }

    func bxFadeOut(){
        if self.alpha == 1 {
            UIViewPropertyAnimator.runningPropertyAnimator(withDuration: 1.0,
                                                           delay: 0,
                                                           options: .curveLinear,
                                                           animations: {self.alpha = 0},
                                                           completion: {finished in print("animation finshed \(finished)")})
        }
    }

}// end of extension

我的完成处理程序有问题吗?

0 个答案:

没有答案