Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImageView subclass needs to handle resize

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.

like image 338
William Entriken Avatar asked Dec 05 '25 13:12

William Entriken


1 Answers

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

like image 200
William Entriken Avatar answered Dec 08 '25 16:12

William Entriken



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!