iOS开发之截屏分享功能

1、监听系统截屏通知

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleUserDidTakeScreenshotNotification:) name:UIApplicationUserDidTakeScreenshotNotification object:nil];

2、监听到截屏后获取屏幕截屏图片

UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
    // 1.开启上下文
    UIGraphicsBeginImageContextWithOptions(window.bounds.size, window.opaque, 0);
    // 2.渲染
    [window drawViewHierarchyInRect:window.bounds afterScreenUpdates:NO];
    // 3.获取图片
    UIImage *snapshotImage=UIGraphicsGetImageFromCurrentImageContext();
    // 4.结束上下文
    UIGraphicsEndImageContext();

3、对图片进行存储本地或者服务器进行分享操作

posted @ 2020-05-09 11:40  kawerd  阅读(1391)  评论(0编辑  收藏  举报