1
在我的應用程序中,用戶可以添加UIImageView
作爲我的UIScrollView
的子視圖。當用戶點擊「保存」按鈕時,我想將我的UIScrollView
的所有內容保存爲UIImage
到照片庫中。在UIImage中轉換UIScrollView的內容
我一直在谷歌上看,但沒有太多關於這個問題。
編輯:下面的代碼做這項工作
CGRect rect = self.mainView.frame;
[self.mainView setFrame:CGRectMake(0, 0, 824, self.mainView.contentSize.height)];
UIGraphicsBeginImageContext(self.mainView.bounds.size);
[self.mainView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image , nil, nil, nil);
[self.mainView setFrame:rect];
不要忘記在渲染之前調整滾動視圖的大小以適應內容,然後將其重新調整爲原始大小。 –
我得到這個錯誤與第二行: '接收器類型'CALayer'例如消息是一個前向聲明' – Benjamin
添加此 - #import –
rishi