iOS 7 UITextView:重新打开应用程序后,nstextattachment的大小增加2倍 [英] iOS 7 UITextView: Size of nstextattachment getting 2x after reopening the application

查看:199
本文介绍了iOS 7 UITextView:重新打开应用程序后,nstextattachment的大小增加2倍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ios7中的Text Kit构建一个音符编辑器。之前我在渲染自定义大小NSTextAttachment时遇到了麻烦,因为它在很大程度上减慢了渲染速度。我通过缩放图像然后将它们添加到textview来解决了这个问题。你可以在
iOS 7.0 UITextView在向其添加图像后变得非常慢
缩放图像后,textview渲染运行正常,没有任何延迟.textview的属性文本存储在核心数据中。在运行的应用程序会话期间,textview正确显示图像。即使保存了属性核心数据中的文本并再次检索它以显示在textview上,图像看起来很好。但是在杀死应用程序并再次运行应用程序之后。图像被放大到2倍大小。在缩放图像时我使用了以下功能并使用[ [UIScreen bounds] scale]以保持图像质量。

I am building a note editor using the Text Kit in ios7. Earlier I had trouble in rendering of custom size NSTextAttachment's as it was slowing down the rendering to a great extent.I solved the issue by scaling the images and then adding them to textview.You can find my answer in iOS 7.0 UITextView gettings terribly slow after adding images to it After scaling the images the textview rendering runs fine without any lag.The attributed text of textview is stored in core data.During a running session of application the textview displays the images correctly.Even after saving the attributed text in the core data and retrieving it again to display on textview,the images look fine.But after killing the app and again running the application.The images get enlarged to 2x size.while scaling the images I used the following function and used [[UIScreen bounds] scale] to maintain the image quality.

- (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;
}

如果我将图像缩放到1.0,图像不会扩展但是图像质量非常糟糕。

If I scale the images to 1.0 the images doesn't expand but the image quality is very bad.

我认为问题出在哪里?
问题出在布局管理器上。

What I Think where the problem lies? The problem lies in the layout manager.

我尝试了什么
我尝试了继承NSLayoutManager并覆盖
- (void)drawGlyphsForGlyphRange :( NSRange)glyphsToShow atPoint:(CGPoint)origin
我看到的是在运行应用程序的新会话时附件大小加倍。如果我尝试检查附件的大小并调整大小。滞后开始再来。
我很长时间没有遇到这个问题。任何建议都会非常感激。

What I have Tried I have tried subclassing the NSLayoutManager and overriding the - (void)drawGlyphsForGlyphRange:(NSRange)glyphsToShow atPoint:(CGPoint)origin What I see is the attachment size is doubling when running a new session of the application.If I try to check the size of attachment and resize it.The lag starts coming again. I am stucked with this problem from a quite time.Any suggestions would be much appreciated.

推荐答案

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

Could the reason due to retina display? If it is retina, you might need to reduce the size by 50% before storing. How about trying this:-

 //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.

这篇关于iOS 7 UITextView:重新打开应用程序后,nstextattachment的大小增加2倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆