********************************************************************
#import <Cocoa/Cocoa.h>
@interface DragView : NSView
@property(nonatomic,assign)BOOL isDragIn;
@end
*************************************************************************
***************************************************************************
#import "DragView.h"
@implementation DragView
- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType,nil]];
if(_isDragIn) {
NSLog(@"拖拽了");
}
// Drawing code here.
}
- (NSDragOperation)draggingEntered:(id)sender{
_isDragIn=YES;
[self setNeedsDisplay:YES];
return NSDragOperationCopy;
}
- (void)draggingExited:(id)sender{
_isDragIn=NO;
[self setNeedsDisplay:YES];
}
- (BOOL)prepareForDragOperation:(id)sender{
_isDragIn=NO;
[self setNeedsDisplay:YES];
return YES;
}
- (BOOL)performDragOperation:(id)sender{
if([sender draggingSource] !=self){
NSArray* filePaths = [[sender draggingPasteboard] propertyListForType:NSFilenamesPboardType];
NSLog(@"文件地址%@",filePaths);
}
return YES;
}
@end
***************************************************************************************
网友评论