0

アクションシートを使用してタブバーアイテムから画面をキャプチャしようとしています。tabbaritem2を押すと、アクションシートが呼び出されます。tabbaritem1からビューコントローラーの画面をキャプチャしたい。このコードを使ってみました。

self.tabBarController.selectedIndex = 0;
UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * imageData = UIImageJPEGRepresentation(image, 1.0);

画面にtabbaritem1が表示されますが、常にtabbaritem2の画面がキャプチャされます...この問題は解決できますか?ありがとう

4

1 に答える 1

0

TabBarControllerのViewController階層に含まれているViewControllerではなく、現在のビューを保存しようとしているようです。このようなことをもっと行います(ViewControllerが階層内のどこにあるかに応じて変更します。

self.tabBarController.selectedIndex = 0;
YourOtherViewController *yourOtherViewController = (YourOtherViewController*)[self.tabBarController objectAtIndex:0]; // This index needs to be changed for your specific controller you wish to screenshot
UIGraphicsBeginImageContext(yourOtherViewController.view.frame.size);
[yourOtherViewController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * imageData = UIImageJPEGRepresentation(image, 1.0);
于 2012-11-19T16:06:06.473 に答える