So I needed to create a simple animation where a view flies off the screen and then flies back in again based on user gestures. My animation code (below) works really well. Actually it works a little too well. Notice how in the enterStage method I do not reposition the view. I just set it's scale to 1. The view flies in and winds up at it's original position just fine. If I do the CGAffineTransformMakeTranslation instead and don't do the scale it also works perfectly. I expected that I would need to keep track of the original size and position myself, but it seems as though this has been somewhat spookily done for me.
This is mysterious.
Where is this data about the original size and position being kept? How would I disable this behavior if I wanted to - like if I wanted the view not to remember its original position?
-(void) exitStage{
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:(void (^)(void)) ^{
CGAffineTransform t = CGAffineTransformMakeTranslation(0, -1000);
self.transform = CGAffineTransformScale (t, 10.0, 10.0);
}
completion:^(BOOL finished){
}];
}
-(void) enterStage{
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:(void (^)(void)) ^{
//self.transform = CGAffineTransformMakeTranslation(0, self.originalYcoord);
self.transform = CGAffineTransformMakeScale(1,1);
}
completion:^(BOOL finished){
}];
}
In your out transition you set its translation to go to (10,10), but in your enter transition, you set its transform to be a 1x1 scale transformation, which contains no translation whatsoever, thus simply undoing your translation by just erasing it
If you wanted to maintain the original transformation and make modifications to it you would need to do something like
self.transform = CGAffineTransformScale(self.transform, 1, 1);
//or
self.transform = CGAffineTransformTranslate(self.transform, 10, 10);