简体   繁体   English

使UIButton动画回到其原始位置,快速IOS

[英]Animate UIButton back to its original position swift IOS

I have wriiten following code to animate my button 我编写了以下代码来为我的按钮制作动画

 UIView.animate(withDuration: 1.0, animations: {

        assistButton.frame = CGRect(x: self.view.frame.maxX - 75, y: self.view.frame.maxY - 120, width: width, height: height)

    })

This code works fine but after some user action I want to animate this button back to original position for that written following code 这段代码可以正常工作,但是在用户执行了一些操作后,我希望将该按钮重新设置为该代码的原始位置的动画

 UIView.animate(withDuration: 1.0, animations: {

    assistButton.frame = CGRect(x: lastX, y: lastY, width: width, height: height)

})

But Above code is not working 但是上面的代码不起作用

lastX and LastY value are initialised in viewDidLoad as below lastX和LastY值在viewDidLoad中初始化,如下所示

    lastX = assistButton.frame.minY
    lastY = assistButton.frame.minX

尝试在viewWillAppear而不是viewDidLoad设置'lastX'和'lastY'。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM