调整大小NSImageView不重绘 [英] Resized NSImageView not redrawing

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

问题描述

我有一个NSImageView从应用程序包加载图像。



它是这样设置的:

  coverImage.image = [NSImage imageNamed:@themeSignEnd.png]; 
coverImage.imageScaling = NSImageScaleNone;
coverImage.imageAlignment = NSImageAlignLeft;

图片显示正常。



NSImageView的大小是基于几个其他因素计算的,然后使用以下代码设置:

  coverImage.frame = CGRectMake 1280-869)/ 2,0,869 *百分比,800); 

这是第一次完成(当应用程序启动时)

NSImageView采用的大小和包含的图像在适当的边框被切断。



不幸的是,当我尝试



NSLogging coverImage.frame

/ code>显示框架本身正确更新。然而,这个视图似乎没有重绘 - 无论是收缩还是当生长框架。此外,当我退出并重新启动应用程序时,NSImageView会绘制正确的边框。



可能会导致此类行为?



NSImageView是否有可能根本不重绘?



我错过了NSImageView的其他怪癖,这可能导致这种行为吗?



编辑



事实证明,只有当 ImageFrameStyle 属性设置为 NSImageFrameNone 。如果框架设置为任何其他,它得到重绘正好。



有没有框架的NSImageViews渲染有什么区别,可以解释这一点吗?

解决方案

因此我找到了一个解决方案,但是它是相当黑的。



在编辑中提到,这个错误只发生在ImageFrameStyle设置为NSImageFrameNone。当我将ImageFrameStyle设置为其他的时候,然后调整它的大小,然后在调整大小后再次将其设置为NSImageFrameNone,事情工作正常:

  [coverImage setImageFrameStyle:NSImageFramePhoto]; 
coverImage.frame = CGRectMake((1280 - 869)/ 2,0,869 * percentage,800);
[coverImage setImageFrameStyle:NSImageFrameNone];

这可行,但不是很漂亮。因此,我将这个问题打开几天,希望找到一个更好的答案。


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?

解决方案

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.

这篇关于调整大小NSImageView不重绘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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