UIImageView变换比例

我有一个UIButton,当按下时,会使UIImageView比例略大,然后回到正常大小。 它正在工作,但我遇到的问题是,按下按钮的次数越多,图像最终会越来越小。

如何更改代码,以便在按下按钮时图像不会变小? 这是我必须将图像缩放得更大然后恢复正常的代码:

[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration: 0.2]; myImage.transform = CGAffineTransformScale(myImage.transform, 1.03, 1.03); [UIView setAnimationDelegate:self]; [UIView commitAnimations]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration: 0.2]; myImage.transform = CGAffineTransformScale(myImage.transform, 0.97, 0.97); [UIView setAnimationDelegate:self]; [UIView commitAnimations]; 

谢谢你的帮助。

这是数学。 将某事物缩放1.03 * 0.97导致比例因子为0.9991而不是1.0 。 使用1.0/1.03作为第二个缩放因子,或者只将myImage.transform设置为身份转换(假设您没有对该视图应用其他转换)。

你试过保存第一次转换吗?

然后,而不是使用CGAffineTransformScale来缩小你的UIImageView你只需使用你保存的变换?

  CGAffineTransform firstTransform = myImage.transform; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration: 0.2]; myImage.transform = CGAffineTransformScale(myImage.transform, 1.03, 1.03); [UIView setAnimationDelegate:self]; [UIView commitAnimations]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration: 0.2]; myImage.transform = firstTransform; [UIView setAnimationDelegate:self]; [UIView commitAnimations]; 

您正受到浮点运算和累积矩阵运算的限制。 您永远无法表示3/100,只能使用0.03330.0333近似它。

对于您的问题,最好将第二个转换设置为CGAffineTransformIdentity