marcosgriselli / ViewAnimator

ViewAnimator brings your UI to life with just one line
MIT License
7.3k stars 488 forks source link

UIView unexpectedly changes position after animation #51

Closed kennyDang closed 5 years ago

kennyDang commented 6 years ago

Expected Behavior

I have a button that uses an AnimationType(.bottom, offset: 10) animation whenever it is tapped. The button should perform the animation and return to its original position.

Actual Behavior

The button performs the animation but changes it's y position with every tap. For example, here is the CGRect of the button for each button animation:

(247.6666666666667, 10.0, 106.33333333333334, 30.0)
(247.6666666666667, 20.0, 106.33333333333334, 30.0)
(247.6666666666667, 30.0, 106.33333333333334, 30.0)
(247.6666666666667, 40.0, 106.33333333333334, 30.0)

Steps to Reproduce the Problem

  1. Programmatic views with autolayout
  2. Press button and animate it: UIView.animate(views: [button], animations: [buttonAnimation], reversed: true, initialAlpha: 1.0, finalAlpha: 0.0, completion: {print(self.button.frame)})

    Specifications

    • Version: 2.2.0
    • Platform: iOS 11
    • Subsystem:
marcosgriselli commented 5 years ago

Well, it's been a long time but better late than never. @kennyDang why is the expected behavior to return to its original position? The reversed property determines if an animation should run in the opposite direction so its end position won't be the original one. I guess this might be slightly confusing since using reversed: false returns the animated view to its original position correctly. But you can work around it using a negative offset for the AnimationType and using reversed: false.