我正在尝试在两个视图控制器之间进行转换。我的Transition类有一个目标视图控制器属性。当我尝试获取目标视图的屏幕截图时,我使用以下方法:
+ (UIImage *)renderImageFromView:(UIView *)view withRect:(CGRect)frame {
// Create a new context the size of the frame
UIGraphicsBeginImageContextWithOptions(frame.size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
// Render the view
[view.layer renderInContext:context];
// Get the image from the context
UIImage *renderedImage = UIGraphicsGetImageFromCurrentImageContext();
// Cleanup the context you created
UIGraphicsEndImageContext();
return renderedImage;
}
所以当我需要这张图片时,我会这样做:
UIImage *image = [UIImage renderImageFromView:destinationController.view withRect:destinationController.view.bounds];
我在一个空的UIViewController上尝试了一下,这个UIViewController有一个橙色的背景和一个标签。 我得到了橙色的背景颜色,但是我没有得到在IB中创建的标签。有没有办法获取我计划显示的新视图的正确截屏?谢谢!