我正在制作一个简单的拖放应用程序,并且在检查时,拖动操作未被注册。我在MainMenu.xib上删除了一个NSView,然后继承了NSView。
DropView.h
#import <Cocoa/Cocoa.h>
@interface DropView : NSView <NSDraggingDestination>
@property (nonatomic, strong) NSImage *image;
@end
DropView.m
#import "DropView.h"
@implementation DropView
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self registerForDraggedTypes: [NSImage imagePasteboardTypes]];
}
return self;
}
- (NSDragOperation) draggingEntered:(id<NSDraggingInfo>)sender{
if ([NSImage canInitWithPasteboard:[sender draggingPasteboard]] && [sender draggingSourceOperationMask] & NSDragOperationCopy ) {
return NSDragOperationCopy;
}
return NSDragOperationNone;
}
- (NSDragOperation) draggingUpdated:(id<NSDraggingInfo>)sender{
NSLog(@"DRAGGING!");
return NSDragOperationCopy;
}
-(void) draggingEnded:(id<NSDraggingInfo>)sender{
NSLog(@"ENDED!");
}
-(void) draggingExited:(id<NSDraggingInfo>)sender{
NSLog(@"EXITED");
}
- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];
// Drawing code here.
}
@end
当我运行它并尝试删除图像时,光标不会更改为+ signed符号。并且没有记录方法。有什么想法吗?
答案 0 :(得分:0)
如果您将图像文件拖到窗口上,(?)那么我认为您需要NSFilenamesPboardType:
[self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];