我已经创建了一个应用程序,其中包含一个Finder子类,它接受直接从ImageView拖放文件/文件夹。
问题是,我现在正在尝试让它接受照片,无论是来自iPhoto或光圈,以及。
我应该注册哪些PboardType%s?
我现在要做的就是:
[self registerForDraggedTypes:
[NSArray arrayWithObjects:NSFilenamesPboardType, nil]];有什么想法吗?
发布于 2012-11-02 23:38:42
使用Pasteboard (来自苹果)向我展示了Aperture给了你文件名/URL以及“光圈图像数据”(不管是什么)。iPhoto似乎只给出了"ImageDataListPboardType",这是一个PLIST。我猜您可以使用NSLog()来查看它的结构并从中提取图像信息。它可能包括文件名/URL信息以及作为数据的实际图像。
发布于 2013-01-17 09:26:34
您注册NSFilenamesPboardType是正确的。要完成任务,请执行以下操作:
1:确保在draggingEntered中接受复制操作。泛型操作不足。
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
NSPasteboard *pasteboard = [sender draggingPasteboard];
if ( [[pasteboard types] containsObject:NSFilenamesPboardType] ) {
if (sourceDragMask & NSDragOperationCopy) {
return NSDragOperationCopy;
}
}
return NSDragOperationNone;
}2:每张照片都有一个文件名。对他们做点什么。
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
NSPasteboard *pasteboard;
NSDragOperation sourceDragMask;
sourceDragMask = [sender draggingSourceOperationMask];
pasteboard = [sender draggingPasteboard];
if ([[pasteboard types] containsObject:NSFilenamesPboardType])
{
NSData* data = [pasteboard dataForType:NSFilenamesPboardType];
if(data)
{
NSString *errorDescription;
NSArray *filenames = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:kCFPropertyListImmutable format:nil errorDescription:&errorDescription];
for (NSString* filename in filenames)
{
NSImage* image = [[NSImage alloc]initWithContentsOfFile:filename];
//Do something with the image
}
}
}
return YES;
}https://stackoverflow.com/questions/13197533
复制相似问题