UIImageView subclass needs to handle resize

佐手、 提交于 2019-12-10 20:20:22

问题


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.

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?

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.


回答1:


Here's a solution:

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

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?


Other ideas that didn't work:

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

  • Listen for key-value observation, discussed at https://groups.google.com/forum/#!topic/ococoa/UojAu8rclwo



来源:https://stackoverflow.com/questions/19216684/uiimageview-subclass-needs-to-handle-resize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!