UIImageView变换比例 [英] UIImageView Transform Scale

查看:79
本文介绍了UIImageView变换比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a UIButton that when pressed, will make a UIImageView scale slightly larger and then back to its normal size. 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];

感谢您的帮助。

推荐答案

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

It's math. Scaling something by 1.03 * 0.97 results in scaling factor of 0.9991 and not 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).

这篇关于UIImageView变换比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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