Closed cmallocfree closed 8 years ago
代码如下(self.contentTextView是YYTextView类型~):
NSRange selectedRange = self.contentTextView.selectedRange; NSMutableAttributedString *text = [self.contentTextView.attributedText mutableCopy]; UIImage *image = [UIImage imageNamed:@"img.png"]; image = [UIImage imageWithCGImage:image.CGImage scale:1.0 orientation:UIImageOrientationUp]; YYTextAttachment *attachment = [[YYTextAttachment alloc] init]; NSMutableAttributedString *attachText = [NSMutableAttributedString attachmentStringWithContent:image contentMode:UIViewContentModeCenter attachmentSize:image.size alignToFont:[UIFont systemFontOfSize: 17.0f] alignment:YYTextVerticalAlignmentBottom]; [text replaceCharactersInRange:selectedRange withAttributedString:attachText]; self.contentTextView.attributedText = text;
之后在self.contentTextView上长按,就无法出现UIMenuController的粘贴选项了。。。我跟了一下代码,_showMenu方法中的[menu setMenuVisible:YES animated:YES];还是执行的,请教一下是怎么回事~~
self.contentTextView
UIMenuController
_showMenu
[menu setMenuVisible:YES animated:YES];
抱歉我复现不了。。如果你还能复现,可以试试跟进到 [menu setTargetRect: 这一行看看 rect 是否在屏幕范围内,如果 rect 有问题我再查一下这个地方。如果这个也没问题,那我就怀疑是系统的原因了(有时在用系统的 textView 或 webView 时,偶尔会遇到弹不出菜单)。
[menu setTargetRect:
Fixed: https://github.com/ibireme/YYKit/commit/3be148151c1dc741a6aa53a31d38a93d19fd4aec
代码如下(self.contentTextView是YYTextView类型~):
之后在
self.contentTextView
上长按,就无法出现UIMenuController
的粘贴选项了。。。我跟了一下代码,_showMenu
方法中的[menu setMenuVisible:YES animated:YES];
还是执行的,请教一下是怎么回事~~