what - Capture image of parent view in iOS 5



xcode constraints (1)

I use the code below to capture an image of the parent view to use as a background in a modal view. It no longer works in iOS 5 (the variable "parentViewImage" below is null. Can someone help?

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

In iOS 5 you need to use presentingViewController instead of parentViewController property.

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