2
"간단한"드래그 내 Mac 응용 프로그램에 & 드래그를 구현하고 싶습니다. 뷰에서 드래그하여 그에 따라 nib 파일에 "MyView"를 입력했습니다. 그러나 콘솔에서 응답을받지 못했습니다 (프로토콜 메서드가 트리거 될 때마다 메시지를 기록하려고합니다)코코아의 드래그 앤 드롭 (<NSDraggingDestination>)이 작동하지 않습니다.
NSView를 서브 클래 싱했습니다 이 같은 :
@interface MyView : NSView <NSDraggingDestination>{
NSImageView* imageView;
}
과 같이 그것을 구현 :
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self registerForDraggedTypes:[NSImage imagePasteboardTypes]];
NSRect rect = NSMakeRect(150, 0, 400, 300);
imageView = [[NSImageView alloc] initWithFrame:rect];
[imageView setImageScaling:NSScaleNone];
[imageView setImage:[NSImage imageNamed:@"test.png"]];
[self addSubview:imageView];
}
return self;
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender{
NSLog(@"entered");
return NSDragOperationCopy;
}
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender{
return NSDragOperationCopy;
}
- (void)draggingExited:(id <NSDraggingInfo>)sender{
NSLog(@"exited");
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender{
NSLog(@"som");
return YES;
}
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
NSPasteboard *pboard = [sender draggingPasteboard];
if ([[pboard types] containsObject:NSURLPboardType]) {
NSURL *fileURL = [NSURL URLFromPasteboard:pboard];
NSLog(@"%@", fileURL);
}
return YES;
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender{
NSLog(@"conclude sth");
}
- (void)draggingEnded:(id <NSDraggingInfo>)sender{
NSLog(@"ended");
}
- (BOOL)wantsPeriodicDraggingUpdates{
NSLog(@"wants updates");
}
- (void)updateDraggingItemsForDrag:(id <NSDraggingInfo>)sender NS_AVAILABLE_MAC(10_7){
}
imagePasteboardTypes = 이미지 콘텐츠 만 –