UIImageView subclass needs to handle resize

2019-07-07 02:58发布

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条回答
爷、活的狠高调
2楼-- · 2019-07-07 03:31

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:

查看更多
登录 后发表回答