我创建了NSView的自定义子类以控制2个NSImageViews。创建图像的代码如下:NSImageView绘图不正确
- (id)initWithFrame:(NSRect)frameRect AndMap:(NSImage *)map AndPlayer:(NSImage *)guyImage
{
self = [super initWithFrame:frameRect];
if (self)
{
NSRect newRect = NSMakeRect(0.0, 0.0, 64.0, 64.0);
NSImageView *theMap = [[NSImageView alloc] initWithFrame:NSMakeRect(0.0, 0.0, frameRect.size.width, frameRect.size.height)];
[theMap setImage:map];
NSImageView *theGuy = [[NSImageView alloc] initWithFrame:newRect];
[theGuy setImage:guyImage];
[self setMapImage:theMap];
[self setPlayerView:theGuy];
[self addSubview:[self mapImage]];
[self addSubview:[self playerView]];
然而,当我告诉视图,其中原点(128,0)一个矩形画,它吸引theMap一个奇怪的偏移,使theGuy's origin is at 128,0,but the map's origin is at something like(128,20)。我找不到为什么会发生这种情况。