2

以下のコードはうまく機能しますが、画面に表示されるUIViewのみを取得します。現在表示されていないUIViewを代わりに取得するにはどうすればよいですか?

ありがとう!

    //Take a screenshot of the view...
UIGraphicsBeginImageContext(View_1.frame.size);
    [View_1.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *View_1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(View_1, nil, nil, nil);

//...and attach it as an image to the email
NSData *myData3 = UIImagePNGRepresentation(View_1);
[picker addAttachmentData:myData3 mimeType:@"image/png" fileName:@"screenshot2"];   
4

1 に答える 1

2

のように非表示にする場合はview.hidden = YES;、描画できません。非表示にする代わりに、スーパービューから削除するか、view.hidden = NO;描画する前に呼び出してから描画したview.hidden = YES;後に呼び出すことができます。

//Take a screenshot of the view...
UIGraphicsBeginImageContext(View_1.frame.size);
//Set it to visible
View_1.hidden = NO;
[View_1.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *View_1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(View_1, nil, nil, nil);
//Hide it again
View_1.hidden = YES;
//...and attach it as an image to the email
NSData *myData3 = UIImagePNGRepresentation(View_1);
[picker addAttachmentData:myData3 mimeType:@"image/png" fileName:@"screenshot2"];
于 2012-06-16T08:35:55.887 に答える