ios捕获截图,但顶部有一个空白(透明),它是状态栏

时间:2012-12-04 01:42:44

标签: ios screenshot statusbar

screenshot, 960*640, but with 44pix transparent status-bar

截图,960 * 640,但图片顶部有44pix透明状态栏。

如何拍摄916像素高的照片?我顶部不需要那个空白栏。

这是我的代码:

-(void)takeScreenShot{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    CGSize imageSize = [[UIScreen mainScreen] bounds].size;
    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]){
        UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0f);
    }else{
        UIGraphicsBeginImageContext(imageSize);
    }
    [window.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData * data = UIImagePNGRepresentation(image);
    //
    NSString *documentsDirectory= [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    NSString *filePath= [documentsDirectory stringByAppendingPathComponent:@"SYS_screen_shot@2x.png"];
    //
    [data writeToFile:filePath atomically:YES];
}

1 个答案:

答案 0 :(得分:0)

您可以使用此权限访问应用程序框架 [[UIScreen mainScreen] applicationFrame]
这将为您提供应用程序在屏幕上的位置


[window.rootViewController.view.layer renderInContext:UIGraphicsGetCurrentContext()];

如果你想要的是你的应用程序的root view,你应该将该视图带到renderInContext。我只是测试了它并且它有效。