2015-02-07 76 views
0

我正在開發一個iOS應用程序,用戶可以在其中添加儘可能多的文本和圖像(就像在iPhone textview上鍵入和添加表情符號)到UITextView快照覆蓋滾動項目

有什麼辦法讓快照覆蓋滾動的項目。我需要將用戶添加到UITextView的任何內容發佈到他/她的Facebook牆上。目前,快照僅捕獲屏幕上可見的內容。我正在使用Swift。

驗證碼:

UIGraphicsBeginImageContextWithOptions(message.contentSize, false, 0); 
message.layer.renderInContext(UIGraphicsGetCurrentContext()); 
let img = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

回答

0

當捕捉快照,使用(0, 0)爲原點和滾動視圖contentSize的大小,而不是使用滾動視圖的bounds直接。這是因爲UIScrollView(及其子類,如UITextView)在滾動時會移動它的bounds,所以bounds矩形僅表示滾動視圖的可見部分。

編輯:看起來UITextView可能不畫的本身是它的邊界之外的部分,所以你可能需要暫時調整其框架,按照this answer

+0

謝謝@Zev艾森伯格,我這樣做了,但我意識到圖像大小是內容的大小,但滾動的項目丟失了。下面是代碼 UIGraphicsBeginImageContextWithOptions(message.contentSize,false,0); message.layer.renderInContext(UIGraphicsGetCurrentContext()),afterScreenUpdates:true); let img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); – 2015-02-07 05:51:02

+0

對不起格式。我試圖弄清楚它是如何在這裏工作的。 – 2015-02-07 05:53:45

+0

最好的辦法是編輯你的原始文章並在那裏添加代碼。 – 2015-02-07 05:55:44