簡體   English   中英

iPhone保存多個視圖截圖

[英]iphone save multiple views screenshot

我有一個UIImagePickerController,向其中添加了一些包含圖像的子視圖。 我需要將整個內容另存為圖像,但無法執行此操作。

為了保存上下文的內容,我使用以下代碼

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

它適用於UIImagePickerController,但是如果我添加子視圖,它將停止在

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

行,在控制台中沒有任何錯誤,只是退出了應用程序。

謝謝!

如果您嘗試獲取屏幕快照中屏幕上的所有內容,那么我會在堆棧溢出中找到以下內容:

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

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

它將抓住窗口上的所有內容。

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM