UIView动画一开始就跳了起来 [英] UIView animation jumps at beginning

查看:314
本文介绍了UIView动画一开始就跳了起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行此代码......

I'm running this code...

[UIView animateWithDuration:0.2
                      delay:0.0
                    options:UIViewAnimationOptionCurveEaseOut
                 animations:^{

                     CGAffineTransform settingsTransform = CGAffineTransformMakeTranslation(self.settingsView.frame.size.width, 0);
                     CGAffineTransform speedTransform = CGAffineTransformMakeTranslation(-self.speedView.frame.size.width, 0);

                     self.settingsView.transform = settingsTransform;
                     self.speedView.transform = speedTransform;

                 } completion:nil];

但是当它运行时,视图会在相反方向上跳转一半,然后再滑动到半个位置正确的方向。

But when it runs the views jump half the transform in the opposite direction before sliding to half a position in the correct direction.

我已经将动画持续时间减慢到5秒,但是初始跳跃是瞬时的,而且转换的一半是错误的方向。

I've slowed down the animation duration to 5 seconds but the initial jump is instantaneous and half the transformation in the wrong direction.

当我使用此代码动画回来时...

When I animate back using this code...

[UIView animateWithDuration:0.2
                      delay:0.0
                    options:UIViewAnimationOptionCurveEaseOut
                 animations:^{
                     self.settingsView.transform = CGAffineTransformIdentity;
                     self.speedView.transform = CGAffineTransformIdentity;
                 } completion:nil];

它完全相同。

结果是最终的移动是所需变换的一半,因为它首先在错误的方向上跳转了一半。

The result is that the final movement is half the desired transform as it jumps half the transform in the wrong direction first.

我真的无法理解为什么这是发生了吗?

I really can't work out why this is happening?

任何想法。

:::

清除一些可能的歧义。

我并不是试图让这些观点反弹回到原来的位置。我正在制作动画的视图就像屏幕边缘的控制面板。当用户按下go时,视图会滑出。当用户按下停止时,面板会滑回视图。

I'm not trying to have these views "bounce" back to where they are. The views I'm animating are like control panel at the edge of the screen. When the user presses "go" the view then slide out of the way. When the user presses "stop" the panels slide back into the view.

至少他们曾经这样做过。由于启用了自动布局(我需要应用程序的其他部分),我不能只改变视图的框架,所以我去了转换路径。

At least they used to. Since enabling auto layout (which I need for other parts of the app) I can't just change the frame of the views so I went the the transform route.

你可以通过将视图粘贴到视图控制器和运行动画的按钮来看到这种效果。

You can see this effect by sticking a view into a view controller and a button to run the animation.

谢谢

推荐答案

好的,再看过WWDC视频,他们说使用AutoLayout时你要做的第一件事就是删除对setFrame的任何调用。

OK, having watched the WWDC videos again they state that one of the first things you have to do when using AutoLayout is to remove any calls for setFrame.

由于屏幕的复杂性,我完全删除了自动布局,现在我正在使用框架位置在屏幕上移动视图。

Due to the complexity of the screen I have removed the Auto-Layout completely and I'm now using the frame location to move the view around the screen.

谢谢

这篇关于UIView动画一开始就跳了起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆