2010-07-12 106 views
0

我有一個UIImagePickerController,我添加了一些包含圖像的子視圖。我需要將整個內容保存爲圖像,但是無法做到這一點。iphone保存多個視圖截圖

爲了節省我使用下面的代碼上下文的內容

UIGraphicsBeginImageContext(self.view.frame.size); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

它的工作原理爲的UIImagePickerController,但如果我添加子視圖停靠在

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

線,沒有任何控制檯中的錯誤,只是退出應用程序。

謝謝!

回答

0

如果你試圖抓住屏幕上的一切在你的屏幕截圖,我發現這個堆棧溢出:

UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow]; 

UIGraphicsBeginImageContext(screenWindow.frame.size); 
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

會搶在窗口上的一切。

希望這會有所幫助。