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、对图片进行存储本地或者服务器进行分享操作


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM