Search code examples
iphoneiosipadcore-animationscreenshot

Capture uiwindow screenshot 30 fps with ui animation


I want to make a tool that will make a video of your app screen to show how app work to the client.
So I want to get window screenshot every 30 - 60 times per second and save it to documents. After app closed create a video from that files and then you will have a video of your app. When your will send app to appstore your will remove or cancel to make a video and app sreenshots.

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


Problem is that I can't capture UIWindow during animation?
How can I do this?


Solution

  • Use this
    [layer.presentationLayer renderInContext:UIGraphicsGetCurrentContext()];
    instead of
    [layer renderInContext:UIGraphicsGetCurrentContext()];