如何将自定义视图放入NSImageWell?
|
我认为图像编辑器是一个完美的开始。无论您单击什么,它都会绘制一个正方形。我的问题是,当您单击其他位置或拖动鼠标时,它只会移动正方形(而不是绘制另一个)。如何在不“拖曳”它的当前内容到处的情况下绘制自定义视图?
这是我的代码:
标头(.h)
NSBezierPath *thePath;
NSColor *theColor;
NSTimer *updateTimer;
NSPoint *mousePoint;
int testInt = 1;
int x = 0;
int y = 0;
@interface test : NSView {
IBOutlet NSView *myView;
IBOutlet NSButton *button;
}
@property (readwrite) NSPoint mousePoint;
@end
.m文件(无论它叫什么)
@implementation test
@synthesize mousePoint;
- (void) mouseDown:(NSEvent*)someEvent {
mousePoint = [someEvent locationInWindow];
NSLog(@\"Location: x= %f, y = %f\", (float)mousePoint.x, (float)mousePoint.y);
x = mousePoint.x;
y = mousePoint.y;
[button setHidden:TRUE];
[button setHidden:FALSE];
[self setNeedsDisplay:YES];
}
- (void) mouseDragged:(NSEvent *)someEvent {
mousePoint = [someEvent locationInWindow];
NSLog(@\"Location: x= %f, y = %f\", (float)mousePoint.x, (float)mousePoint.y);
x = mousePoint.x;
y = mousePoint.y;
[button setHidden:TRUE];
[button setHidden:FALSE];
[self setNeedsDisplay:YES];
}
- (void) drawRect:(NSRect)rect; {
thePath = [NSBezierPath bezierPathWithRect:NSMakeRect(x, y, 10, 10)];
theColor = [NSColor blackColor];
[theColor set];
[thePath fill];
}
@end
为什么不起作用?
没有找到相关结果
已邀请:
1 个回复
壬驴拿歪竞
对象存储在某个位置(我建议使用
),然后遍历数组并绘制每个矩形。 查看当前代码,应实现
并将x和y坐标的
对象存储在
中。然后在
中循环遍历
个对象的数组并绘制每个对象。