使用UI动画捕获uiwindow屏幕截图30 fps



我想制作一个工具,制作应用程序屏幕的视频,以显示应用程序如何向客户端工作。
所以我想每秒每 30 - 60 次获取一次窗口屏幕截图并将其保存到文档中。应用程序关闭后,从该文件创建视频,然后您将拥有应用程序的视频。当您将应用程序发送到应用商店时,您将删除或取消以制作视频和应用程序快照。

//Get list of document directories in sandbox
    NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDirectory, YES);
    //Get one and only document directory from that list
    self.documentFolder = [documentDirectories objectAtIndex:0];
    self.images = [[NSMutableArray alloc] init];
    //Append passed in file name to that directory, return it
    _counter = 0;
    self.timerCapture = [NSTimer scheduledTimerWithTimeInterval: 1.0f/30.0f
                                             target: self
                                           selector: @selector(getWindowCapture:)
                                           userInfo: nil
                                            repeats: YES];

- (UIImage *)captureScreen {
    CALayer *layer;
    layer = self.window.layer;
    UIGraphicsBeginImageContextWithOptions(self.window.bounds.size, NO, 1.0f); 
    [layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *screenImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return screenImage;
}


问题是我无法在动画过程中捕获UIWindow?
我该怎么做?

使用这个

[layer.presentationLayer renderInContext:UIGraphicsGetCurrentContext()];而不是
[layer renderInContext:UIGraphicsGetCurrentContext()];

它可能会帮助你。

https://github.com/hackiftekhar/IQProjectVideo

有一个缺点,它不能捕获当前视图控制器动画。我正在尝试解决此问题。

最新更新