Capturing a UIView without using renderInContext:

I want to create a video from my screen, and for this I am going to capture the view, but for some reason I do not want to use renderInContext:. I am using now drawViewHierarchyInRect:, but it is limited to iOS 7, and my application supports earlier versions of iOS. Will I be fined for using drawViewHierarchyInRect:?

this is my code

UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0);
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
+2
source share
1 answer

, renderInContext, , iOS 7, ( drawViewHierarchyInRect iOS 7.0, ). , , drawViewHierarchyInRect, , renderInContext, :

UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0);

if ([self respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) {
    BOOL success = [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
    NSAssert(success, @"drawViewHierarchyInRect failed");
} else {
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];
}

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

, iOS 7+, , , .

+3

All Articles