簡體   English   中英

迅捷動畫不起作用

[英]Swift Animation Not Working

一旦發生某種情況,我試圖將UILabel和UIButton移到應用程序的屏幕上,但是,當我使用動畫執行此操作時,它不起作用,並且當應該執行動畫時,組件不起作用移動到屏幕上。 這是動畫的代碼:

UIView.animateWithDuration(2) { () -> Void in
                    self.label.center = CGPointMake(self.view.center.x, self.label.center.y)
                    self.again.center = CGPointMake(self.view.center.x, self.again.center.y)
                }

任何有關此問題的幫助將不勝感激!

您應該嘗試一下。 使用layoutIfNeeded()將重新放置所有內容。

UIView.animateWithDuration(2) { () -> Void in

                 self.label.center = CGPointMake(self.view.center.x, self.label.center.y)
                 self.again.center = CGPointMake(self.view.center.x, self.again.center.y)
                 self.view.layoutIfNeeded()
            }

嘗試這個!

UIView.animateWithDuration(1.0,
delay: 2.0,
options: .CurveEaseInOut ,
animations: {
self.label.center = CGPointMake(self.view.center.x, self.label.center.y)
self.again.center = CGPointMake(self.view.center.x, self.again.center.y)    },
completion: { finished in
  println("Bug moved left!")
  self.faceBugRight()
})
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM