UIImageView子类需要处理调整大小 [英] UIImageView subclass needs to handle resize

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

问题描述

我正在创建UIImageView子类以显示音频波形。方法是加载文件,进行数学运算,保存PNG文件,然后 self.image = thePNG 。这样做的好处是,在调整大小或重新绘制UIImageView时,它将拉伸PNG并迅速拉伸。

I am creating a UIImageView subclass to display an audio waveform. The approach is to load the file, do math, save a PNG file and then self.image = thePNG. The nice part about this is that on a resize or repaint the UIImageView will stretch the PNG and stretch quickly.

现在,如果图像扩展得太多,则需要重新计算波形以避免可见像素化。由于我们知道 UIImageView不会调用 drawRect ,在调整大小期间是否有一种方法可以调用,以便我可以确定是否需要重绘?

Now if the image is expanded too much then I need to recalculate the waveform to avoid visible pixelation. Since we know that UIImageView does not call drawRect, is there a method that is called during resize so that I can decide if redrawing is necessary?

PS重新计算时,在计算完新图像后,我会淡入新图像。希望这对象Google Earth这样的用户将是无缝的。

P.S. When recalculating I will be fading in the new image after it is calculated. Hopefully this will be seamless to the user like Google Earth.

推荐答案

这是一个解决方案:

- (void)layoutSubviews
{
    [super layoutSubviews];
    NSLog(@"%@", NSStringFromCGRect(self.frame));
}

与此取舍的是,不会为动画,正如David Jeske在>是否有UIView调整大小事件中指出的那样?

The trade off with this is that it is not called for each frame of an animation, as pointed out by David Jeske in Is there a UIView resize event?

其他无效的想法:


  • 覆盖 setFrame:(CGRect)frame

  • Override setFrame:(CGRect)frame discussed at Is there a UIView resize event?

收听键值观察,在< a href = https://groups.google.com/forum/#!topic/ococoa/UojAu8rclwo rel = nofollow noreferrer> https://groups.google.com/forum/#!topic/ococoa/UojAu8rclwo

这篇关于UIImageView子类需要处理调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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