나는 이미지 편집기에 완벽한 출발이라고 생각한 것을 만들었습니다. 클릭 할 때마다 정사각형이 그려집니다. 내 문제는 다른 장소를 클릭하거나 마우스를 끌 때 사각형을 이동한다는 것입니다 (다른 사각형을 그리는 대신). 현재의 내용을 어디서나 "드래그"하지 않고 어떻게 커스텀 뷰를 그릴 수 있습니까?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
하지 않는 이유는이 작품 : 여기에
내 코드?
고맙습니다. 그게 작동 할 것 같네요 – Justin
완벽하게 작동했습니다! 고마워요! – Justin