2016-04-17 66 views
0

学习斯威夫特动画ImageViews跑进今天这个:与延迟

我有我创建网点为3张图片:

@IBOutlet weak var bookImageView: SpringImageView! 
@IBOutlet weak var sketchImageView: SpringImageView! 
@IBOutlet weak var xcodeImageView: SpringImageView! 

当我点击按钮动作learnButtonDidTouch我希望他们动画:

bookImageView马上

sketchImageView 0,2延迟

xcodeImageView 0,2延迟

在我搜索我只找到了使用UIView.animationWithDuration代码,但我还没有得到远远不够明白,为什么我不能在我的ImageViews直接使用.animationWithDuration。这里有什么选择?找不到任何关于使用.animate().animation的时间,因此我猜测我必须在UIView上使用.animationWithDuration。但在这种情况下,我该怎么做?

这是当我按下按钮的代码:

@IBAction func learnButtonDidTouch(sender: AnyObject) { 
    sketchImageView.animation = "pop" 
    xcodeImageView.animation = "pop" 
    bookImageView.animation = "pop" 
    sketchImageView.animate() 
    xcodeImageView.animate() 
    bookImageView.animate() 
} 

回答

0

animateWithDurationcompletionHandler:。在第一个动画的完成处理程序中,执行第二个动画;在第二个动画的完成处理程序中,执行第三个动画。

此外,animateWithDuration有一个delay参数,所以您可以轻松延迟第二个和第三个动画。

0

你绝对可以使用UIView.animateWithDuration。以下是一些代码。

UIView.animateWithDuration(0.2, delay: 0, options: nil, animations: {() -> Void in 
    //bookImageView animation 
}, completion: 
    UIView.animateWithDuration(0.2, delay: 0, options: nil, animations: {() -> Void in 
    //sketchImageView animation 
    }, completion: 
     UIView.animateWithDuration(0.2, delay: 0, options: nil, animations: {() -> Void in 
      //xcodeImageView animation 
     }, completion: nil) 
    ) 
)