iOS设备上“屏幕外”时,UIText View的内容不呈现

问题描述 投票:2回答:3

我正在使用UITextView呈现一些文本。我正在使用以下代码来渲染主视图,以设置更高的输出分辨率(我还将所有子视图按相同的比例缩放)。

    UIGraphicsBeginImageContext(CGSizeMake(ImageView.frame.size.width*4, ImageView.frame.size.height*4));
[outputView setFrame:CGRectMake(outputView.frame.origin.x, outputView.frame.origin.y, outputView.frame.size.width*4, outputView.frame.size.height*4)];
     [[outputView layer] renderInContext:UIGraphicsGetCurrentContext()];

在缩放方面效果很好。唯一的问题是,如果UITextView元素处于“ off sccreen”状态,则它将无法正确呈现。因此,没有* 4比例因子,所有内容都可以正常渲染,但与此同时,被推离屏幕的UITextView元素将无法正确渲染(大多数情况下为空白)。

是否有方法可以覆盖它,强制其渲染?

感谢阅读

ios xcode uitextview
3个回答
2
投票

执行此操作:

  CGAffineTransform newtransform = CGAffineTransformMakeScale(4.0, 4.0);
  self.view.transform = newtransform;
  CGRect newFrame = CGRectApplyAffineTransform(self.view.frame, newtransform);
  //CGSize fittingSize = [yourTextView sizeThatFits:CGSizeZero];
  UIGraphicsBeginImageContext(newFrame.size);
  [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
  UIImahe *capImage = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();

1
投票

最终使用标签进行渲染。因此,UIText视图用于在界面中显示以及进行交互,但是它们被暂时隐藏并由标签替换以进行渲染。


0
投票

[基于Mrwolfy的答案,我还设法通过将UITextView的内容复制到UILabel中来解决了类似的问题-无论出于何种原因,它的行为似乎都有些不同。这是我使用的代码:

UILabel* contents = [[UILabel alloc] initWithFrame:textView.frame];
[textView.superview addSubview:contents];
contents.numberOfLines = 0;
contents.lineBreakMode = NSLineBreakByWordWrapping;
contents.attributedText = textView.attributedText;

textView.hidden = YES;

// Now render the scrollview in slices
for (CGFloat y = 0; y < scrollView.contentSize.height; y += scrollView.frame.size.height) {
    [scrollView setContentOffset:CGPointMake(0, y) animated:NO];
    [scrollView.layer renderInContext:context];
}

textView.hidden = NO;

[contents removeFromSuperview];

© www.soinside.com 2019 - 2024. All rights reserved.