`

iOS 截屏

    博客分类:
  • oc
 
阅读更多
+ (UIImage *)getImageOfView:(UIView *)view
{
    UIImage *screenImage;
//    UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0.0);
    SEL aSelector = NSSelectorFromString(@"drawViewHierarchyInRect:afterScreenUpdates:");
    if ([view respondsToSelector:aSelector]) {
        NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[view methodSignatureForSelector:aSelector]];
        [inv setSelector:aSelector];
        [inv setTarget:view];
        
        BOOL y = YES;
        CGRect r = view.bounds;
        [inv setArgument:&r atIndex:2]; //arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation
        [inv setArgument:&y atIndex:3]; //arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation
        
        [inv invoke];
    } else {
        [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    }
    
    screenImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return screenImage;
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics