iPad: Move UIView with animation, then move it back

前端 未结 2 498
后悔当初
后悔当初 2021-02-11 03:06

I have the following code in a UIView subclass that will move it off the screen with an animation:

float currentX = xposition; //variables that store where the U         


        
相关标签:
2条回答
  • 2021-02-11 03:27

    UIView transform isn't additive; I suggest that to move it back you instead do:

    self.transform = CGAffineTransformIdentity;
    

    The docs say (about updating the frame):

    "Warning: If this property is not the identity transform, the value of the frame property is undefined and therefore should be ignored."

    0 讨论(0)
  • 2021-02-11 03:41

    Assigning to a transform will cause the old one to disappear. To return to the original position, assign the identity transform to it.

    self.transform = CGAffineTransformIdentity;
    

    (Or better, just change the .frame instead of changing the .transform.)

    0 讨论(0)
提交回复
热议问题