gpt4 book ai didi

iphone - 弹出窗口的屏幕截图不清晰

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:26 24 4
gpt4 key购买 nike

我正在开发一个 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();

最佳答案

请尝试更改:

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;
}

关于iphone - 弹出窗口的屏幕截图不清晰,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14195640/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com