I have a NSImageView which loads an image from the application bundle.
It is setup as such:
coverImage.image = [NSImage imageNamed:@"themeSignEnd.png"];
coverImage.imageScaling = NSImageScaleNone;
coverImage.imageAlignment = NSImageAlignLeft;
The image displays just fine.
The size of the NSImageView is calculated based on several other factors and then set using this code:
coverImage.frame = CGRectMake((1280 - 869) / 2, 0, 869 * percentage, 800);
This works perfectly fine the first time it is done (when the application launches).
The NSImageView takes on the size and the image contained is cut off at the appropriate border.
Unfortunately, when I try to resize the NSImageView while the application is running (using the same code above), it won't visibly update.
NSLogging the coverImage.frame
shows that the frame itself is updated correctly. However, the view does not seem to be redrawn - neither when shrinking nor when growing the frame. Additionally, when I quit and restart the app, the NSImageView draws the correct border.
What could cause such behavior?
Is it possible that the NSImageView is simply not redrawn? If so, how can I force a redrawing?
Are there any other quirks of NSImageView that I missed which can lead to this behavior?
edit:
It turns out this bug only happens when the ImageFrameStyle
property is set to NSImageFrameNone
. If the frame is set to anything else, it gets redrawn just fine. Unfortunately, we need the image to be displayed without a frame.
Is there any difference in rendering for NSImageViews with and without frames that could explain this?
I had very similar problem with NSImageView
imageFrameStyle
property set to NSImageFrameNone
. It occurred that the problem was in Auto-Layout settings. You can check my question here: NSImageView won't scale image down if frame style is NSImageFrameNone
So I found a way around this, however it is fairly hackish.
As mentioned in the edit, this bug only occurs with ImageFrameStyle set to NSImageFrameNone. When I set the ImageFrameStyle to something else, then resize it, then set it to NSImageFrameNone again after resizing, things work fine:
[coverImage setImageFrameStyle: NSImageFramePhoto];
coverImage.frame = CGRectMake((1280 - 869) / 2, 0, 869 * percentage, 800);
[coverImage setImageFrameStyle: NSImageFrameNone];
This works but isn't very pretty. Thus I'll leave the question open for a couple more days in hope to find a better answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With