iPad的:移动的UIView动画,然后移回 [英] iPad: Move UIView with animation, then move it back

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

问题描述

我有一个UIView子类以下code,将与动画将它关闭屏幕:

I have the following code in a UIView subclass that will move it off the screen with an animation:

float currentX = xposition; //variables that store where the UIView is located
float currentY = yposition;

float targetX = -5.0f - self.width;
float targetY = -5.0f - self.height;

moveX = targetX - currentX; //stored as an instance variable so I can hang on to it and move it back
moveY = targetY - currentY;

[UIView beginAnimations:@"UIBase Hide" context:nil];
[UIView setAnimationDuration:duration]; 
self.transform = CGAffineTransformMakeTranslation(moveX,moveY);
[UIView commitAnimations];

它的工作好了。我已经改变了targetX / Y为0,看它是否确实移动到指定的点,它的作用。

It works just great. I've changed targetX/Y to 0 to see if it does indeed move to the specified point, and it does.

问题是,当我尝试移动视图回到它原来的地方:

The problem is when I try and move the view back to where it was originally:

moveX = -moveX;
moveY = -moveY;

[UIView beginAnimations:@"UIBase Show" context:nil];
[UIView setAnimationDuration:duration];
self.transform = CGAffineTransformMakeTranslation(moveX,moveY);
[UIView commitAnimations];

这看跌期权大约3倍的UIView至于它应该。因此,鉴于通常被放在了屏幕的右侧(取决于它在哪里)。

This puts the UIView about 3x as far as it should. So the view usually gets put off the right side of the screen (depending on where it is).

有什么用CGAffineTransforMakeTranslation功能,我应该知道吗?我读的文档,并从我所知道的,它应该做的事情,我希望它做的事。

Is there something with the CGAffineTransforMakeTranslation function that I should know? I read the documentation, and from what I can tell, it should be doing what I'm expecting it to do.

任何人对如何解决这一问题有何建议?谢谢你。

Anyone have a suggestion of how to fix this? Thanks.

推荐答案

分配到变换将导致旧的消失。返回到原来的位置,分配的身份转换到它

Assigning to a transform will cause the old one to disappear. To return to the original position, assign the identity transform to it.

self.transform = CGAffineTransformIdentity;

(或更好,只是改变了 .frame ,而不是改变 .transform

这篇关于iPad的:移动的UIView动画,然后移回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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