이미지를 프로그래밍 방식으로 가져 와서 저장 한 후 그 이미지를 드래그하면 어떻게되는지 알 수 없습니다.
삭제 된 이미지는 NSTextAttachment로 NSTextStorage에 추가됩니다. 따라서 삭제 된 이미지에 액세스하려면 textStorage의 내용을 반복하고 이미지 파일을 준수하는 첨부 파일이 있는지 확인해야합니다.
내가이 경우
이 길을 갈하려는 경우 당신은 확실히를 NSTextView을 확장하고 - (void)performDragOperation:(id<NSDraggingOperation>)sender
방법을 덮어에 의해 삭제 된 파일을 처리 할 수 있습니다를 관리하는 드래그 앤 드롭에 관한 몇 가지 방법을 구현해야합니까 Apple의 Drag and Drop Programming Topics 문서를 읽어 보시기 바랍니다.
서브 클래 싱의 팬이 아니기 때문에이 문제에 대한 대답은 NSAttributedString 범주를 사용하여 연결된 이미지의 NSArray를 반환합니다. 어느 아래의 코드로 해결 될 수있다 : 당신이 GIT를 사용하는 경우
#import "NSAttributedString+AttachedImages.h"
@implementation NSAttributedString (AttachedImages)
- (NSArray *)images
{
NSMutableArray *images = [NSMutableArray array];
NSRange effectiveRange = NSMakeRange(0, 0);
NSTextAttachment *attachment;
CFStringRef extension;
CFStringRef fileUTI;
while (NSMaxRange(effectiveRange) < self.length) {
attachment = [self attribute:NSAttachmentAttributeName atIndex:NSMaxRange(effectiveRange) effectiveRange:&effectiveRange];
if (attachment) {
extension = (__bridge CFStringRef) attachment.fileWrapper.preferredFilename.pathExtension;
fileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, extension, NULL);
if (UTTypeConformsTo(fileUTI, kUTTypeImage)) {
NSImage *theImage = [[NSImage alloc] initWithData:attachment.fileWrapper.regularFileContents];
[theImage setName:attachment.fileWrapper.preferredFilename];
[images addObject:theImage];
}
}
}
return images.copy;
}
@end
, 내 Github repository의 코드를 복제 할 수 있습니다.
도움이 되었기를 바랍니다.