因此,我需要创建一个简单的动画,其中 View 飞出屏幕,然后根据用户手势再次飞回。我的动画代码(如下)效果非常好。事实上,它的效果有点太好了。请注意,在 EnterStage 方法中,我没有重新定位 View 。我只是将其比例设置为 1。 View 飞入并最终回到其原始位置,效果很好。如果我改为执行 CGAffineTransformMakeTranslation 并且不执行缩放,它也可以完美工作。我预计我需要自己跟踪原始大小和位置,但似乎这对我来说有点令人毛骨悚然。
这很神秘。
有关原始大小和位置的数据保存在哪里? 如果我想,我该如何禁用此行为 - 就像我希望 View 不记住其原始位置一样?
-(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){
}];
}
最佳答案
在输出转换中,您将其翻译设置为转到 (10,10),但在输入转换中,您将其变换设置为 1x1 比例变换,其中不包含任何翻译,因此只需简单地撤消翻译即可删除它
如果您想保持原始转换并对其进行修改,您需要执行类似的操作
self.transform = CGAffineTransformScale(self.transform, 1, 1);
//or
self.transform = CGAffineTransformTranslate(self.transform, 10, 10);
关于ios - UIView animateWithDuration 返回原始状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15686080/