ios - UIView animateWithDuration 返回原始状态

标签 ios cgaffinetransform

因此,我需要创建一个简单的动画,其中 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/

相关文章:

objective-c - 调用指定返回类型和参数的内联 block

xcode - iOS 非仿射变换

ios - CGAffineTransformMakeTranslation 与 CGRectOffset 动画

iphone - CGAffineTransform 旋转方向错误

iphone - 翻转时如何恢复保存的变换

ios - 如何在Objective C中一天或24小时后显示本地通知?

ios - 在 iOS 上构建的 Unity 中,GetFileAsync 无法从存储中下载

ios - WKWebView 在 iOS 8 下不加载本地文件

ios - 在渲染tableview swift 2之前添加一行

objective-c - 在动画帧更改后使用变换缩放 UIView 会导致 UIView 在缩放之前跳回到原始帧