[英]UIImageView Transform Scale
I have a UIButton that when pressed, will make a UIImageView scale slightly larger and then back to its normal size. 我有一个UIButton,当按下时,会使UIImageView比例略大,然后回到正常大小。 It's working, but I'm running into a problem where the image eventually keeps getting slightly smaller the more you press the button. 它正在工作,但我遇到的问题是,按下按钮的次数越多,图像最终会越来越小。
How can I change the code so that the image doesn't get smaller as you press the button? 如何更改代码,以便在按下按钮时图像不会变小? Here's the code I have to scale the image slightly larger and then back to normal: 这是我必须将图像缩放得更大然后恢复正常的代码:
[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];
Thanks for any help. 谢谢你的帮助。
It's math. 这是数学。 Scaling something by 1.03 * 0.97
results in scaling factor of 0.9991
and not 1.0
. 将某事物缩放1.03 * 0.97
导致比例因子为0.9991
而不是1.0
。 Either use 1.0/1.03
as your second scaling factor or just set myImage.transform
to the identity transform (assuming you are not applying other transformations to that view). 使用1.0/1.03
作为第二个缩放因子,或者只将myImage.transform
设置为身份转换(假设您没有对该视图应用其他转换)。
Have you tried saving first transform? 你试过保存第一次转换吗?
And then instead of using CGAffineTransformScale
to shrink your UIImageView
you just use your saved 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];
You are suffering from a limitation in floating point arithmetic and cumulative matrix operations. 您正受到浮点运算和累积矩阵运算的限制。 You will never be able to represent 3/100, only approximate it with values like, 0.03
, 0.033
, and 0.0333
. 你将永远无法代表3/100,只有像,价值接近其0.03
, 0.033
和0.0333
。
For your problem it would be better to set the second transform to the CGAffineTransformIdentity
对于您的问题,最好将第二个转换设置为CGAffineTransformIdentity
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.