是否可以在单个NSView
中绘制多个NSImages
?
到目前为止,在 NSView
子类中进行绘制的过程如下:
- (void)drawRect:(NSRect)dirtyRect
{
[image drawInRect:NSMakeRect(0.0f, 0.0f, 100.0f, 100.0f) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0f];
}
//to change the current image
- (void)newImage:(NSImage *)image_
{
[image release];
image = [image_ retain];
[self setNeedsDisplay:YES];
}
但这只是为了绘制一张图像。有人可以帮忙吗? 谢谢。
最佳答案
您必须保留对需要绘制的图像的引用。
@interface MyView : NSView
{
NSMutableArray* images;
}
然后,使用合适的 API 添加图像,例如:
@implementation MyView
- (void) addImage: (NSImage *) anImage
{
[images addObject: anImage];
[self setNeedsDisplay: YES];
}
在drawRect:
中,您可以迭代图像
并绘制全部/部分图像。
关于objective-c - NSView 中有多个 NSImage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9528048/