我正在使用 ios7 中的文本工具包构建一个笔记编辑器。早些时候,我在渲染自定义大小的 NSTextAttachment 时遇到了麻烦,因为它在很大程度上减慢了渲染速度。我通过缩放图像然后将它们添加到 textview 解决了这个问题。您可以在中找到我的答案iOS 7.0 UITextView 添加图像后变得非常慢 https://stackoverflow.com/questions/23026975/ios-7-0-uitextview-gettings-terribly-slow-after-adding-images-to-it缩放图像后,textview 渲染运行良好,没有任何延迟。textview 的属性文本存储在核心数据中。在应用程序运行会话期间,textview 正确显示图像。即使在将属性文本保存在核心数据中并检索它之后再次在文本视图上显示,图像看起来不错。但是在终止应用程序并再次运行应用程序后。图像放大到 2 倍大小。在缩放图像时,我使用以下函数并使用 [[UIScreenbounds]scale] 来维护图像质量。
- (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,图像不会扩展,但图像质量非常差。
我认为问题出在哪里?问题出在布局管理器上。
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%。试试这个怎么样:-
//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.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)