UIText视图的内容在“时不呈现”;“屏幕外”;在iOS设备上

UIText视图的内容在“时不呈现”;“屏幕外”;在iOS设备上,ios,xcode,uitextview,Ios,Xcode,Uitextview,我正在使用UITextView渲染一些文本。我使用以下代码将主视图渲染得更大,以将输出设置为更高的分辨率(我还按相同的因子缩放所有子视图) 在缩放方面效果很好。唯一的问题是,如果UITextView元素处于“脱离屏幕”状态,它将无法正确渲染。因此,在没有*4比例因子的情况下,所有内容都可以很好地渲染,但有了它,推离屏幕的UITextView元素无法正确渲染(大部分只是空白) 有没有办法覆盖它,强制它渲染 感谢阅读请执行以下操作: CGAffineTransform newtransform

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

在缩放方面效果很好。唯一的问题是,如果UITextView元素处于“脱离屏幕”状态,它将无法正确渲染。因此,在没有*4比例因子的情况下,所有内容都可以很好地渲染,但有了它,推离屏幕的UITextView元素无法正确渲染(大部分只是空白)

有没有办法覆盖它,强制它渲染

感谢阅读

请执行以下操作:

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

最后使用标签,只是为了渲染。因此,UIText视图用于显示在界面中,并用于交互,但它们暂时隐藏,并由用于渲染的标签替换。

以Wolfy先生的答案为基础,我还通过将
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];

UILabel*contents=[[UILabel alloc]initWithFrame:textView.frame];
[textView.superview添加子视图:内容];
contents.numberOfLines=0;
contents.lineBreakMode=NSLineBreakByWordWrapping;
contents.attributedText=textView.attributedText;
textView.hidden=是;
//现在以切片的形式渲染滚动视图
对于(CGFloat y=0;y
谢谢。我在输出整个父视图的完美图像时没有遇到任何问题,该视图恰好包含任意数量的UIText视图和UIimage视图。问题是在如上所述缩放视图之后。不确定你的代码中是否有修复程序,但不管怎样,如果我错过了,请告诉我。非常感谢-我为此奋斗了几个小时,这为我解决了它!
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];