alskipp / ASScreenRecorder

Record iOS screen contents to .mp4 video file
MIT License
558 stars 127 forks source link

UIAlertview not visible #12

Closed pfeidemine closed 8 years ago

pfeidemine commented 9 years ago

Hello,

First of all, this is not an issue, but rather a feature that I would like to have. Second, thanks so much for this great recorder, works so nice.

I have noticed that the UIAlertView is not shown in the final recording.

This is my code :

I can see the selection of the cell, but not the alert.

Also another thing. Is it possible to display an overlay over the keyboard that will be visible only on the recording. I want to accomplish something like a security thing for when a user inputs his credentials, the keyboard and maybe the textfields should be covered, but only in the video. I've seen that lookback.io does something similar but I don't really know how.

Thank you !

alskipp commented 9 years ago

Perhaps UIAlertView doesn't appear in the app's list of UIWindows?. If this is the case, I'm not sure if there's a way of dealing with it.

As for displaying an overlay over the keyboard, you'll have to make an alteration to the delegate method writeBackgroundFrameInContext: (or create a new delegate method writeOverlayFrameInContext).

A quick hack would be to change the following lines in the .m file:

        if (self.delegate) {
            [self.delegate writeBackgroundFrameInContext:&bitmapContext];
        }
        // draw each window into the context (other windows include UIKeyboard, UIAlert)
        // FIX: UIKeyboard is currently only rendered correctly in portrait orientation
        dispatch_sync(dispatch_get_main_queue(), ^{
            UIGraphicsPushContext(bitmapContext); {
                for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
                    [window drawViewHierarchyInRect:CGRectMake(0, 0, _viewSize.width, _viewSize.height) afterScreenUpdates:NO];
                }
            } UIGraphicsPopContext();
        });

to:

        // draw each window into the context (other windows include UIKeyboard, UIAlert)
        // FIX: UIKeyboard is currently only rendered correctly in portrait orientation
        dispatch_sync(dispatch_get_main_queue(), ^{
            UIGraphicsPushContext(bitmapContext); {
                for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
                    [window drawViewHierarchyInRect:CGRectMake(0, 0, _viewSize.width, _viewSize.height) afterScreenUpdates:NO];
                }
            } UIGraphicsPopContext();
        });
        if (self.delegate) {
            [self.delegate writeBackgroundFrameInContext:&bitmapContext];
        }

The delegate drawing will now occur on top of the app window (for my use case I needed to draw live video and overlay the app controls over the video, that's why the delegate draws beneath the app window by default).

Then in your view controller, implement the delegate method [ASScreenRecorder sharedInstance].delegate = self;:

- (void)writeBackgroundFrameInContext:(CGContextRef*)contextRef {
  // create overlay CGRect
  CGRect overlayRect = …
  // set overlay color
  CGContextSetFillColor(contextRef, …
  // fill rect with overlay color in `contextRef`
  CGContextFillRect(contextRef, overlayRect)
}
pfeidemine commented 9 years ago

Thank you so much for the quick answer ! The solution with overlay works perfectly !

The one for UIAlertView didn't had time to test, will come back with an reply to that also in a couple of days.