gpt4 book ai didi

Swift 将动画与完成合二为一

转载 作者:搜寻专家 更新时间:2023-11-01 07:23:52 25 4
gpt4 key购买 nike

我有 5 个动画,它们只是页面上的对象,在用户点击登录按钮后会掉落。我对每个后续的延迟增加了 0.3。我想知道是否有一种更简洁、更高效的方式来编写这段代码。

    func loggedInAnimate1(){

UIView.animateWithDuration(2,
delay: 0.0,
options: .CurveEaseIn,
animations: {
self.newUser.center.y += self.view.bounds.width

}, completion: nil)

}

func loggedInAnimate2(){

UIView.animateWithDuration(2,
delay: 0.3,
options: .CurveEaseIn,
animations: {
self.loginButton.center.y += self.view.bounds.width

}, completion: nil)

}

func loggedInAnimate3(){

UIView.animateWithDuration(2,
delay: 0.6,
options: .CurveEaseIn,
animations: {
self.loginPasswordTextField.center.y += self.view.bounds.width

}, completion: nil)

}

func loggedInAnimate4(){

UIView.animateWithDuration(2,
delay: 0.9,
options: .CurveEaseIn,
animations: {
self.loginEmailTextField.center.y += self.view.bounds.width

}, completion: nil)

}

func loggedInAnimate5(){

UIView.animateWithDuration(3,
delay: 1.2,
options: .CurveEaseIn,
animations: {
self.logo.center.y += self.view.bounds.height

}, completion: nil)

}

最后一个我想调用另一个函数...这一切都可能吗?谢谢

最佳答案

您可以使用完成闭包来触发下一个动画。这样您就不需要使用延迟,并且可以嵌套动画。

UIView.animateWithDuration(2, delay: 0, options: .CurveEaseIn, animations: {
self.newUser.center.y += self.view.bounds.width
}, completion: { _ in
UIView.animateWithDuration(2, delay: 0, options: .CurveEaseIn, animations: {
self.loginButton.center.y += self.view.bounds.width
}, completion: { _ in
// And so on...
})
})

关于Swift 将动画与完成合二为一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37232862/

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