捕获带有状态栏的iPhone屏幕? [英] Capture iPhone screen with status bar included?

查看:134
本文介绍了捕获带有状态栏的iPhone屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来捕捉包含顶级状态栏的iPhone屏幕截图,我目前正在使用以下代码:

I am looking for a way to capture a screenshot on the iPhone with the top status bar included, I am currently using the following code:

    UIGraphicsBeginImageContext(self.view.bounds.size); //self.view.window.frame.size
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

以上代码成功获取iPhone UIView的屏幕截图,但不包括顶级状态栏(In它的位置只是一个空白的20px空间。

The above code sucessfully takes a screenshot of the iPhone UIView but does not include the top status bar (In its place is just a blank 20px space).

推荐答案

从iOS 7开始,你可以这样做而不使用私有API 使用

As of iOS 7, you can do this without the use of private APIs using

UIView *screenshotView = [[UIScreen mainScreen] snapshotViewAfterScreenUpdates:NO];

请参阅我对这个问题的回答:

See my answer to this question:

在iOS 7中移动状态栏

这篇关于捕获带有状态栏的iPhone屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆