UIImageView动画和UIView animateKeyframesWithDuration同时进行

时间:2016-09-28 14:34:09

标签: ios swift animation uiimageview uikit

我正在同时运行两个动画并获得意想不到的结果。

我有一个动画是UIImage设置中的一系列.png像这样...

func animateImages(duration: NSTimeInterval) -> Void {

    loadingView.animationImages = loadingAnimatedImages
    loadingView.animationDuration = duration
    loadingView.animationRepeatCount = 0
    loadingView.hidden = false
    loadingView.startAnimating()
}

然后使用UIView.animateKeyframesWithDuration这样设置的动画...

func animateView(duration: NSTimeInterval) -> Void {
    circle.layer.anchorPoint = CGPoint(x: 0.5, y: 0.5)
    circle.layer.cornerRadius = animationCircleView.frame.size.width/2
    circle.backgroundColor = UIColor.blue
    animationCircleView.addSubview(circle)
    circle.transform = CGAffineTransformMakeScale(0.5, 0.5)

    UIView.animateKeyframesWithDuration(duration, delay: 0.0, options: .CalculationModeLinear, animations: { 
        UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: .33, animations: { 
            self.circle.transform = CGAffineTransformMakeScale(1.0, 1.0)
            self.circle.alpha = 1.0
        })
        UIView.addKeyframeWithRelativeStartTime(.33, relativeDuration: .33, animations: { 
            self.circle.alpha = 0.5
        })
        UIView.addKeyframeWithRelativeStartTime(.66, relativeDuration: .33, animations: { 
             self.circle.transform = CGAffineTransformMakeScale(0.9, 0.9)
        })

        }) { (success) in
             animationCircleView.hidden = true
    }
}

然后用相同的方法调用它们。

func animate() -> Void {
   animateView(2.0)
   animateImages(2.0)
}

两个动画都运行,图像动画始终运行良好,但UIView动画始终运行延迟。我在想它与主线程锁相关,但不确定。

有谁知道解决方案?解决?切换到UIView动画的drawRect而不是动画?

任何想法都赞赏!

0 个答案:

没有答案