nsattributedstring を使用して NSTextAttachment として uitextview 内に UIimage を挿入しました。
現在、attrbutestring のデフォルト プロパティが原因で、画像で長押しイベントが発生しています。
つまり、UIImage を長押しすると、UIActionsheet が表示され、「SAVE IMAGE」または「COPY」のオプションが表示されます。
私はこれのためのコードを書いていませんでした..
UIIMAGEを長押しして実際に欲しいのは、チャットのようなwhatappのように、その小さなUIIMAGEをフルスクリーンで開きたいということです。ユーザーが画像を送信し、ユーザーがその画像をクリックすると、フルスクリーンで表示されます。
このnstextattachmentのクリックイベントをカスタマイズするのを手伝ってください。
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"Somestring"];
CGRect rect = CGRectMake(0,0,100,100);
UIGraphicsBeginImageContext( rect.size );
[image drawInRect:rect];
UIImage *picture1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImagePNGRepresentation(picture1);
UIImage *img=[UIImage imageWithData:imageData];
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
textAttachment.image =img;
NSAttributedString *attrStringWithImage = [NSAttributedString attributedStringWithAttachment:textAttachment];
[attributedString replaceCharactersInRange:NSMakeRange(0,0) withAttributedString:attrStringWithImage];
UITextView *messageContentView=[[UITextView alloc] init];
messageContentView.attributedText=attributedString;