iPhone 帮助重置动画 CGAffineTransform?
嗨,我对 CGAffineTransform 动画完全感到困惑。我想做的就是将精灵从右侧位置移动到左侧位置。当它停止时,我想“重置”它,即将它移回到开始的位置。如果应用程序退出(使用多任务处理),我想在启动时再次重置位置并重复动画。
这就是我用来制作动画的东西。
[UIImageView animateWithDuration:1.5
delay:0.0
options:(UIViewAnimationOptionAllowUserInteraction |
UIViewAnimationOptionCurveLinear
)
animations:^(void){
ufo.transform = CGAffineTransformTranslate(ufo.transform, -270, 100);
}
completion:^(BOOL finished){
if(finished){
NSLog(@"ufo finished");
[self ufoAnimationDidStop];
}
}];
据我了解,CGAffineTransforms 只是在视觉上使精灵看起来像是移动了,但实际上并没有移动它。 “重置”位置时
因此,当我尝试使用ufo.center = CGPointMake(355, 70);
它没有做任何事情。
我确实有一些工作;
如果我调用ufo.transform = CGAffineTransformTranslate(ufo.transform, 270, -100); ,
它会重置。问题是,如果我在动画中途退出应用程序,那么当它重新启动时,它不一定从头开始,也不会去正确的地方,它基本上会发疯!
有没有办法只删除应用于它的任何变换?我正在考虑只使用计时器,但是当这种方法应该起作用时,这似乎很愚蠢。我已经为此苦苦挣扎了一段时间,所以任何帮助将不胜感激。
谢谢
Hi I am totally confused with CGAffineTransform animations. All I want to do is move a sprite from a position on the right to a position on the left. When it has stopped I want to "reset" it i.e. move it back to where it started. If the app exits (with multitasking) I want to reset the position again on start and repeat the animation.
This is what I am using to make the animation..
[UIImageView animateWithDuration:1.5
delay:0.0
options:(UIViewAnimationOptionAllowUserInteraction |
UIViewAnimationOptionCurveLinear
)
animations:^(void){
ufo.transform = CGAffineTransformTranslate(ufo.transform, -270, 100);
}
completion:^(BOOL finished){
if(finished){
NSLog(@"ufo finished");
[self ufoAnimationDidStop];
}
}];
As I understand it the CGAffineTransforms just visually makes the sprite look like it's moved but doesn't actually move it. Therefore when I try and "reset" the position using
ufo.center = CGPointMake(355, 70);
it doesn't do anything.
I do have something working, if I call
ufo.transform = CGAffineTransformTranslate(ufo.transform, 270, -100);
it resets. The problem is if I exit the app half way through the animation then when it restarts it doesn't necessarily start from the beginning and it doesn't go the the right place, it basically goes crazy!
Is there a way to just remove any transforms applied to it? I'm considering just using a timer but this seems silly when this method should work. I;ve been struggling with this for some time so any help would be much appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对视图应用变换实际上并不会改变视图的中心或边界;而是会改变视图的中心或边界。它只是改变视图在屏幕上显示的方式。您想要将变换设置回 CGAffineTransformIdentity 以确保它看起来像“正常”。您可以在开始动画之前将其设置为您想要的动画效果。
Applying a transform to a view doesn't actually change the center or the bounds of the view; it just changes the way the view is shown on the screen. You want to set your transform back to CGAffineTransformIdentity to ensure that it looks like "normal." You can set it to that before you start your animation and set it to what you want it to animate to.