如何确定UIViewAnimation层次结构视图。迅速

时间:2015-01-17 00:18:13

标签: swift uiview

我有2个动画,按下2个不同的按钮即可触发。当他们真正占据相同的空间并且彼此重叠时,我如何确定我首先看到的那个。是否有一些代码可用于确定首先显示UIImageView的层次结构?

这是我正在处理的一个例子。我有一个"闪电"图像和云图像。

//Lightning



@IBAction func lightningOne(sender: UIButton) {

    self.darkCloud.hidden = false

    let lightning = UIImageView()
    lightning.image = UIImage(named: "lightning")
    lightning.frame = CGRect(x:-41, y:29, width:30, height:105)
    self.view.addSubview(lightning)

    let options = UIViewAnimationOptions.CurveEaseIn

    UIView.animateWithDuration(0.1, delay: 0.5, options: options, animations: {

        lightning.frame = CGRect(x: -45, y: 34, width: 30, height: 105)

        }, completion: { animationFinished in

            self.darkCloud.hidden = false
            UIView.animateWithDuration(0.0, delay: 0.0, options: options, animations: {
                self.view.addSubview(lightning)
                lightning.frame = CGRect(x: 41, y: 34, width: 30, height: 105)

                }, completion: { animationFinished in
                    self.darkCloud.hidden = false
                    UIView.animateWithDuration(0.7, delay: 0.0, options: options, animations: {
                        self.view.addSubview(lightning)
                        lightning.frame = CGRect(x: 41, y: 35, width: 30, height: 105)

                        }, completion: { animationFinished in
                            lightning.removeFromSuperview()
                            self.darkCloud.hidden = true
                    })
            })
    })
}

以下是我用来展示云的代码。

 // Clouds

 func movingClouds() {

    let options = UIViewAnimationOptions.Repeat

    let cloud = UIImageView()
    cloud.image = UIImage(named: "cloud1")
    cloud.frame = CGRect(x: -80, y: 110, width: 78, height: 42)
    self.view.addSubview(cloud)
 UIView.animateWithDuration(140.0, delay: 0.0, options: options, animations: {
        cloud.frame = CGRect(x: 350, y: 110, width: 78, height: 42)
        }, completion: nil)
 }

当我触发闪电图像并碰巧相互交叉时,如何确保闪电图像显示在云端?

0 个答案:

没有答案