0

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 = assistButton.frame.minY
    lastY = assistButton.frame.minX
amodkanthe
  • 4,345
  • 6
  • 36
  • 77

1 Answers1

1

Try setting 'lastX' and 'lastY' in viewWillAppear instead of viewDidLoad.

Reid
  • 1,109
  • 1
  • 12
  • 27