问题描述
You can see a screenshot of the issue here
我在 UITextView 内部添加了一个 NSTextAttachment,但是,在我插入图像后,随机对于某些照片,编辑时光标变得非常大。我尝试了以下修复但没有运气:
NSAttributedString *attachmentimage = [NSAttributedString attributedStringWithAttachment:attachment];
[attachmentimage boundingRectWithSize:image.size options:NsstringDrawingUsesLineFragmentOrigin | NsstringDrawingUsesFontLeading context:nil];
NSAttributedString *spacer = [[NSAttributedString alloc]initWithString:@"\n\n"];
NSAttributedString *prefixAttachmentString = spacer;
if([self.text isEqualToString:@""]){prefixAttachmentString = [[NSAttributedString alloc]initWithString:@""];} //no spacer if text empty
NSMutableAttributedString *attachmentString = [[NSMutableAttributedString alloc]initWithAttributedString:prefixAttachmentString];
[attachmentString appendAttributedString:attachmentimage];
NSKernAttributeName
NSMutableParagraphStyle *paragraphSytle = [[NSMutableParagraphStyle alloc]init];
NSLog(@"image attachment: %@",attachmentimage);
NSLog(@"image cursor size: %f",image.size.height);
paragraphSytle.paragraphSpacingBefore = 0.0;
paragraphSytle.linespacing = 10;
[attachmentString addAttributes:@{@"attachmentName" : name,NSParagraphStyleAttributeName : paragraphSytle}
range:NSMakeRange((int)prefixAttachmentString.length,1)];
[attachmentString addAttributes:self.typingAttr range:NSMakeRange((int)prefixAttachmentString.length,1)];
[attachmentString appendAttributedString:spacer];
[self.textStorage insertAttributedString:attachmentString
atIndex:(int)(self.selectedRange.location)];
[attachmentString addAttributes:self.typingAttr range:NSMakeRange(0,attachmentString.length)];
self.selectedRange = NSMakeRange(self.selectedRange.location+(int)attachmentString.length,self.selectedRange.length);
[self.textStorage endEditing];```
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)