在做屏幕截图时,可以将view的layer渲染到context上,然后保存为图片。iOS 还提供了一种更高效的方式:
?
戴维营教育代码1 2 3 4 5 6 7 8 9 | - (UIImage *)snapshot:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES , 0);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates: YES ];
UIImage *p_w_picpath = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return p_w_picpath;
}
|