我有一个 NBox 的子类,我想在一个名为 dragBox 的画布上拖动它。我不明白为什么以下代码没有触发 draggingEntered 。我得到了一张漂亮的后退图像,但没有一个目的地代表被解雇。为什么?
-(void) awakeFromNib
{
[[self superview] registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
}
-(void) mouseDown:(NSEvent *)theEvent
{
[self dragImage:[[NSImage alloc] initWithContentsOfFile:@"/Users/bruce/Desktop/Untitled-1.png"] at:NSMakePoint(32, 32) offset:NSMakeSize(0,0) event:theEvent pasteboard:[NSPasteboard pasteboardWithName:NSDragPboard] source:self slideBack:YES];
}
-(NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender // validate
{
NSLog(@"Updated");
return [sender draggingSourceOperationMask];
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
NSLog(@"Drag Entered");
return [sender draggingSourceOperationMask];
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
NSLog(@"Move Box");
[self setFrameOrigin:[sender draggingLocation]];
return YES;
}
-(BOOL) prepareForDragOperation:(id<NSDraggingInfo>)sender
{NSLog(@"Prepared");
return YES;
}