【发布时间】:2011-05-29 11:04:56
【问题描述】:
我创建了一个自定义的 NSView 子类来控制 2 个 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 的原点位于 128,0,但 theMap 的原点位于 (128,20) 之类的位置。我找不到发生这种情况的任何原因。
【问题讨论】:
标签: objective-c cocoa nsimageview