如何以编程方式在iOS设备中为SOS拍摄屏幕截图?

时间:2016-07-04 07:33:42

标签: ios api screenshot photo send

enter image description here使用新的API

snapshotViewAfterScreenUpdates
resizableSnapshotViewFromRect
drawViewHierarchyInRect

使用这些我想以任何格式拍照并需要发送。

1 个答案:

答案 0 :(得分:0)

试试这个

UIView *screenshotView = [[UIScreen mainScreen] snapshotViewAfterScreenUpdates:NO];
UIImage *snapshotImage = [self imageFromView:screenshotView];

- (UIImage *)imageFromView:(UIView *)view
{
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0.0);
    [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return img;
}