SDScreenshotCapture 是一个可以用于捕获 exclusion iOS status bar 中的 app 窗口截图的类。它包括直接将截图作为 UIImage
获取、通过 UIActivityViewController
分享、保存到相册或直接写入 Documents 目录中的应用程序沙盒中的方法。
此类在 iOS 7 中最为有用,用于捕获启动图像或为 App Store 中的截图做准备。我们编写它是为了准备我们编写的工具 Status Magic 的图像,该工具将完美状态栏放在 App Store 列表中对应用的有效图片上。
导入 SDScreenshotCapture 类,使用下面的方法之一来捕获截图
// Screenshot and show share sheet
[SDScreenshotCapture takeScreenshotToActivityViewController];
// Screenshot and store to camera roll
[SDScreenshotCapture takeScreenshotToCameraRoll];
// Screenshot and store to documents directory
[SDScreenshotCapture takeScreenshotToDocumentsDirectory];
这些方法可以从任何地方调用,以下是一些在一般方式中触发截图的建议
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureRecognized:)];
tapGesture.numberOfTouchesRequired = 4;
[self.window addGestureRecognizer:tapGesture];
return YES;
}
- (void)tapGestureRecognized:(UITapGestureRecognizer *)tapGesture
{
[SDScreenshotCapture takeScreenshotToActivityViewController];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDidTakeScreenshot:) name:UIApplicationUserDidTakeScreenshotNotification object:nil];
return YES;
}
- (void)userDidTakeScreenshot:(NSNotification *)notification
{
[SDScreenshotCapture takeScreenshotToActivityViewController];
}
注意:不幸的是,如果使用此方法触发 SDScreenshotCapture 截图,则无法停止原始截图的捕获。
只需导入 SDScreenshotCapture 类。或者,这个类也可以作为 CocoaPod 使用
pod 'SDScreenshotCapture'
在 Example
文件夹中运行 SDScreenshotCapture.xcodeproj
项目。
SDScreenshotCapture 由 Dave Verwer 和 Greg Spiers 编写,他们来自 Shiny Development。
SDScreenshotCapture 可在 MIT 许可证下使用。有关详细信息,请参阅 LICENSE 文件。