I am new to mac developing. I am developing an app about richEdit by subclassing NSTextView. In my customized textView, I can insert image like .bmp .jpeg .png. Code is like this:
NSTextAttachment* attachment;
NSImage *image = [[NSImage alloc] initWithContentsOfFile:strRealPath]; //strRealPath is the absolute path of image;
attachment = [[NSTextAttachment alloc] init];
NSTextAttachmentCell *cell = [[NSTextAttachmentCell alloc] initImageCell:image];
[attachment setAttachmentCell:cell];
NSMutableAttributedString *attachmentString = (NSMutableAttributedString*)[NSMutableAttributedString attributedStringWithAttachment:attachment];
NSTextStorage* textStorage = [self textStorage];
[textStorage appendAttributedString:attachmentString];
[self didChangeText]; //self is my customized texview
Through this method, those image work well, but when the image is gif, the animation doesn't show. So, I tried this to display:
NSTextAttachment* attachment;
NSImage *image = [[NSImage alloc] initWithContentsOfFile:strRealPath]; //strRealPath is the absolute path of image;
attachment = [[NSTextAttachment alloc] init];
NSTextAttachmentCell *cell = [[NSTextAttachmentCell alloc] initImageCell:image];
NSMutableAttributedString *attachmentString = (NSMutableAttributedString*)[NSMutableAttributedString attributedStringWithAttachment:attachment];
NSTextStorage* textStorage = [self textStorage];
[textStorage appendAttributedString:attachmentString];
[self didChangeText]; //self is my customized texview
Finally,the gif animation works. But my problem comes: the right-click context menu doesn't show when I click or select the gif image, but other type image's context menu works well.