我创建了一个自定义的 NSView 子类来控制 2 个 NSImageViews。创建图像的代码如下:
- (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的原点位于 128,0,但theMap的原点类似于 ( 128,20)。我找不到发生这种情况的任何原因。