在iOS 5中捕获父视图的图像

在iOS 5中捕获父视图的图像,ios,uiimage,core-graphics,ios5,Ios,Uiimage,Core Graphics,Ios5,我使用下面的代码捕获父视图的图像,以用作模式视图中的背景。它在iOS 5中不再工作(下面的变量“parentViewImage”为空。有人能帮忙吗 // grab an image of our parent view UIView *parentView = self.parentViewController.view; UIGraphicsBeginImageContext(parentView.bounds.size); [parentView.layer renderInContext:

我使用下面的代码捕获父视图的图像,以用作模式视图中的背景。它在iOS 5中不再工作(下面的变量“parentViewImage”为空。有人能帮忙吗

// grab an image of our parent view
UIView *parentView = self.parentViewController.view;
UIGraphicsBeginImageContext(parentView.bounds.size);
[parentView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *parentViewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

在iOS 5中,您需要使用
presentingViewController
而不是
parentViewController
属性

UIView *parentView = self.presentingViewController.view;
UIGraphicsBeginImageContext(parentView.bounds.size);
[parentView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *parentViewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

+我也有同样的问题。我把你的答案从问题中移到了答案中。你应该接受它,让人们知道它是正确的。