popover的屏幕截图不清楚

时间:2013-01-07 12:09:09

标签: iphone objective-c ios ipad uipopovercontroller

我正在开发一个ios应用程序,我需要截取图像截图,但我无法在屏幕上截取弹出窗口的正确截图。 这是我的实际图像

enter image description here

在拍摄截图后我得到了以下图片

enter image description here

我拍摄图像的代码如下

    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();

1 个答案:

答案 0 :(得分: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;
}