[英]Swift Animation Not Working
I am trying to move a UILabel and a UIButton onto the screen of my app once something happens, however, when I use an animation to do this, it doesn't work and when the animation is supposed to happen, the components don't move onto the screen. 一旦发生某种情况,我试图将UILabel和UIButton移到应用程序的屏幕上,但是,当我使用动画执行此操作时,它不起作用,并且当应该执行动画时,组件不起作用移动到屏幕上。 Here is the code for the animation:
这是动画的代码:
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)
}
Any help with this problem will be greatly appreciated! 任何有关此问题的帮助将不胜感激!
You should try this. 您应该尝试一下。 Using layoutIfNeeded() will reposition everything.
使用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()
}
Try this! 尝试这个!
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.