实现类似(Home+关机键)截图效果)

#pragma mark -
#pragma mark - 截图保存按钮事件
- (void)rightButtonAction:(id)sender{
    //获取当前窗口对象
    UIImage * image = [self getNormalImage:self.view.window];
    UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
    [MBProgressHUD showSuccess:@"截图成功" toView:self.view];
}

- (UIImage *)getNormalImage:(UIView *)view{
    //保存原图
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT), NO, 0.0);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:context];
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

猜你喜欢

转载自blog.csdn.net/yjs_13597468160/article/details/79361347