我使用下面的代码捕获父视图的图像,以用作模态视图中的背景。它不再适用于iOS 5(下面的变量“parentViewImage”为null。有人可以帮忙吗?
// grab an image of our parent view
UIView *parentView = self.parentViewController.view;
UIGraphicsBeginImageContext(parentView.bounds.size);
[parentView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *parentViewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
答案 0 :(得分:5)
在iOS 5中,您需要使用presentingViewController
而不是parentViewController
属性。
UIView *parentView = self.presentingViewController.view;
UIGraphicsBeginImageContext(parentView.bounds.size);
[parentView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *parentViewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();