#pragma mark - 屏幕快照 - (UIImage *)convertViewToImage:(UIView *)view { //https://github.com/alskipp/ASScreenRecorder 錄屏代碼 // 第二個參數表示是否非透明。若是須要顯示半透明效果,需傳NO,不然YES。第三個參數就是屏幕密度了 UIGraphicsBeginImageContextWithOptions(view.bounds.size,YES,[UIScreen mainScreen].scale); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } - (UIImage *)snapsHotView:(UIView *)view { UIGraphicsBeginImageContextWithOptions(view.bounds.size,YES,[UIScreen mainScreen].scale); [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; }