基本的に、MyClassに属するCustomViewLayoutと呼ばれるUIViewのスクリーンショットを撮りたいと思います。MyClassのビューはNormalViewに割り当てられます。したがって、私が呼び出すself.view
と、NormalViewを参照します。viewCustom
CustomViewLayoutのアウトレットであるプロパティを作成しました。とにかく、CustomViewLayoutのスクリーンショットを撮りたいのですが、これを試しました。
UIGraphicsBeginImageContextWithOptions(self.viewCustom.bounds.size, self.viewCustom.opaque, 0.0);
[self.viewCustom.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
その画像は、アプリ内メール(MFMailComposeViewController
)内に表示/添付されます。また、機能しません。内部に疑問符が付いた青いボックスが表示されます。これは、画像が読み取れないことを意味していると思います。スクリーンショットコードを次のようにスクリーンショットに変更すると、アプリ内メールの画像添付コードに問題がないことがわかりself.view
ます。
UIGraphicsBeginImageContextWithOptions(self.viewCustom.bounds.size, self.viewCustom.opaque, 0.0);
[self.viewCustom.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
その後、正常に動作します。では、他のビューのスクリーンショットを撮るにはどうすればよいですか?助けてくれてありがとう!