3

画像のスクリーンショットを撮る必要があるiOSアプリを開発していますが、画面上のポップオーバーの正しいスクリーンショットを撮ることができません。これが私の実際のイメージです

ここに画像の説明を入力

スクリーンショットを撮った後、次の画像が表示されます

ここに画像の説明を入力

画像をキャプチャするための私のコードは次のとおりです

    UIWindow *topWindow = nil;

    topWindow = [[[UIApplication sharedApplication] delegate] window];

    CGSize size = CGSizeZero;
    if(view == nil){
        size =  [[topWindow.rootViewController view] bounds].size;
    }else{
        size =  [view bounds].size;
    }

    if([UIScreen instancesRespondToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0f){
        UIGraphicsBeginImageContextWithOptions(size,NO,2.0f);
    }else{
        UIGraphicsBeginImageContext(size);
    }

    if(view == nil){
        // Put everything in the current view into the screenshot
        [[[[topWindow subviews] objectAtIndex:0] layer] renderInContext:UIGraphicsGetCurrentContext()];

        //Code for capturing popover
        [[[topWindow subviews].lastObject layer] renderInContext:UIGraphicsGetCurrentContext()];

        }
    }else{
        // Put everything in the current view into the screenshot
        [[view layer] renderInContext:UIGraphicsGetCurrentContext()];
    }

    // Save the current image context info into a UIImage
    UIImage *imageToBeEdited = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
4

1 に答える 1

0

変更してみてください:

if(view == nil)
{
   size =  [[topWindow.rootViewController view] bounds].size;
}else{
   size =  [view bounds].size;
}

に :

if(view == nil)
{
    size =  [[topWindow.rootViewController view] bounds].size;
}else{
    size =  view.frame.size;
}
于 2013-01-07T12:27:39.887 に答える