gpt4 book ai didi

ios - 如何等到动画在 Swift 中完成?

转载 作者:可可西里 更新时间:2023-10-31 23:57:12 25 4
gpt4 key购买 nike

在我的测验的下一个问题加载之前,我尝试让按钮“摇动”。

动画看起来像

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 block ,你应该使用带有 delayoptions 参数的结构作为出色地。

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()
})

关于ios - 如何等到动画在 Swift 中完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28441152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com