iOS 7 UITextView:重新打开应用程序后,nstextattachment的大小增加2倍

nic*_*k28 7 nslayoutmanager uitextview nstextattachment ios7 textkit

我正在使用ios7中的Text Kit构建一个注释编辑器.早些时候,我遇到了麻烦,在自定义尺寸的渲染NSTextAttachment的AS它呈现放缓的大extent.I解决这个问题通过缩放图像,然后将它们添加到textview.You可以找到我的回答 的iOS 7.0的UITextView gettings后非常慢向图像添加图像 缩放图像后,文本视图渲染运行正常,没有任何滞后.文本视图的属性文本存储在核心数据中.在应用程序运行时,textview正确显示图像.即使在核心中保存属性文本后也是如此数据并再次检索以显示在textview上,图像看起来很好.但是在杀死应用程序并再次运行应用程序之后.图像被放大到2倍大小.在缩放图像时我使用了以下功能并使用了[[UIScreen bounds]比例]以保持图像质量.

- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {

     UIGraphicsBeginImageContextWithOptions(newSize, NO, [UIScreen mainScreen].scale);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}
Run Code Online (Sandbox Code Playgroud)

如果我将图像缩放到1.0,图像不会扩展,但图像质量非常差.

我认为问题出在哪里? 问题在于布局管理器.

我曾尝试 我试图子类NSLayoutManager并重写 - (空白)drawGlyphsForGlyphRange:(NSRange)glyphsToShow atPoint:(CGPoint)原产 我看到的是运行application.If我尝试的一个新的会话时,附件大小加倍检查附件的大小并调整大小.滞后开始再次出现.我很快就遇到了这个问题.任何建议都会非常感激.在此输入图像描述 在此输入图像描述

Ric*_*cky 4

难道是视网膜显示的原因?如果是视网膜,您可能需要在存储之前将尺寸缩小 50%。试试这个怎么样:-

 //Original Size that you want to store
CGSize imageSize = CGSizeMake(320.0f, 320.0f);

//Make the image 50% of the size for retina
if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] &&([UIScreen mainScreen].scale == 2.0)) {
    // Retina display
    imageSize = CGSizeMake(160.0f, 160.0f);
}

UIImage * storeImage = [self imageWithImage:self.image scaledToSize:imageSize]
//TODO: Store this image locally or whatever you want to do.
Run Code Online (Sandbox Code Playgroud)