NSWindow支持Drag-and-Drop
来源:互联网 发布:js substring 编辑:程序博客网 时间:2024/05/20 23:35
在NSView中,通过registerForDraggedTypes:来支持Drag-and-Drop。
[self registerForDraggedTypes:@[NSColorPboardType, NSFilenamesPboardType]];
对于NSWindow,通过awakeFromNib来支持Drag-and-Drop
@interface ONMainWindow () <NSDraggingDestination>
@end
@implementation ONMainWindow
- (void)awakeFromNib {
[self registerForDraggedTypes:@[NSFilenamesPboardType]];
}
#pragma mark - NSDraggingDestination
// 拖放显示图标
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
return NSDragOperationCopy;
}
- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender {
return NSDragOperationCopy;
}
// 拖放操作
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
NSPasteboard *pboard = [sender draggingPasteboard];
NSArray *filenames = [pboard propertyListForType:NSFilenamesPboardType];
if (1 == filenames.count) {
if ([[NSApp delegate] respondsToSelector:@selector(application:openFile:)]) {
return [[NSApp delegate] application:NSApp openFile:[filenames lastObject]];
}
}
return NO;
}
我们在MainWindow.xib中,把Window设置为ONMainWindow。
然后,拖放文件到Windows窗口上,就可以再performDragOperation:中收到我们拖放的文件名或文件路径。
[0] __NSCFString *@"/Volumes/Info/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleOSX10.9.CoreReference.docset/Contents/Resources/Documents/samplecode/CocoaDragAndDrop/Listings"0x0000608000185480
- NSWindow支持Drag-and-Drop
- Drag and Drop
- 学习drag and drop
- 关于drag and drop
- html5 Drag and drop
- Ajax Drag and Drop
- QT5 drag and drop
- HTML5 Drag and Drop
- drag and drop学习
- android - Drag and Drop
- html5 Drag and Drop
- Qt Drag and Drop
- drag and drop(拖拽)
- Drag And Drop 进阶
- drag and drop 事件
- Richfaces的Drag Drop支持
- Drag and drop with Javascript
- Drag and Drop between Controls
- Hadoop面试题 (网上收集版带答案)
- 面向对象基本先关概念
- Floyed-Warshall-求最短路
- HTML5 aside元素
- leetCode练习(187)
- NSWindow支持Drag-and-Drop
- java保留n位小数
- Debug
- golang连接mysql数据库
- About Me
- 什么叫句柄(Handle)?
- 进程的死锁
- 网络爬虫之链接网页
- 卷积神经网络(CNN)前向传播算法