[英]Lottie Animation: Stop Loop but wait until animation has finished
[英]How to wait until an animation is finished in Swift?
在我的测验的下一个问题要加载之前,我试着让按钮“摇晃”。
动画看起来像
var timer = NSTimer()
UIView.animateWithDuration(0.1, animations: {
self.IMGVIEWcat.center = CGPointMake(self.IMGVIEWcat.center.x + 2, self.IMGVIEWcat.center.y)
})
UIView.animateWithDuration(0.2, animations: {
self.IMGVIEWcat.center = CGPointMake(self.IMGVIEWcat.center.x - 4, self.IMGVIEWcat.center.y)
})
UIView.animateWithDuration(0.3, animations: {
self.IMGVIEWcat.center = CGPointMake(self.IMGVIEWcat.center.x + 2, self.IMGVIEWcat.center.y)
})
在此之后调用以下函数
func QueryInformations(){
println("QueryInformationsStart")
self.ActivityIndicator.hidden = false
ObjectIDsArrayCount = ObjectIDsArray.count
var RandomQuestion = Int(arc4random_uniform(ObjectIDsArray.count + 0))
var QuestionID:String = ObjectIDsArray[RandomQuestion]
var query : PFQuery = PFQuery(className: "AddonQuiz")
query.getObjectInBackgroundWithId(QuestionID){
(ObjectHolder : PFObject!, error : NSError!) -> Void in
...
现在动画开始但是下一个问题加载即时,是否有一些容易等待初学者实现“等待”直到动画完成?
我试着设定
var complet == true
在动画中
并在查询功能
if complet = true {....
但这对我来说不起作用,我也发现了一些关于完成处理程序的信息,但是在我的代码中没有得到它。
如果要在动画结束时使用completion
块,则应使用带有delay
和options
参数的构造。
UIView.animateWithDuration(0.3, delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations: {
// put here the code you would like to animate
self.IMGVIEWcat.center = CGPointMake(self.IMGVIEWcat.center.x + 2, self.IMGVIEWcat.center.y)
}, completion: {(finished:Bool) in
// the code you put here will be compiled once the animation finishes
QueryInformations()
})
在您正在调用的函数上使用completion
块:
UIView.animateWithDuration(0.3, animations: {
self.IMGVIEWcat.center = CGPointMake(self.IMGVIEWcat.center.x + 2, self.IMGVIEWcat.center.y)
}, completion: {(finished:Bool) in
QueryInformations()
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.