iOS小demo之快速截图

xiaoxiao2021-02-28  127

从某个view上截图大家比较熟悉的方法是:

    UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0);

    

    [view.layer renderInContext:UIGraphicsGetCurrentContext()];

    

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

在iOS7之后有个更快捷、效率更高的方式:

    UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0);

    

    [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];

    

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

还有个强大的api可以逆转:

UIView *newView = [view snapshotViewAfterScreenUpdates:YES];

转载请注明原文地址: https://www.6miu.com/read-23808.html

最新回复(0)