苹果有提供方法,可以注册监听,当用户有截屏操作的时候会通知我们:
1、注册:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didTakeScreenshot:) name:UIApplicationUserDidTakeScreenshotNotification object:nil];
2、回调:
- (void)didTakeScreenshot:(NSNotification *)notification {
}
3、再次一并献上截屏数据获取
- (NSData*)screenshotWithRect:(CGRect)rect{
UIView *view = [UIApplication sharedApplication].windows[0].rootViewController.view;
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen mainScreen].scale);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return UIImagePNGRepresentation(image);
}
博客介绍了iOS系统中监听用户截屏操作的方法,包括注册监听和回调函数的设置。同时还给出了获取截屏数据的代码,通过一系列操作将截屏转换为PNG格式的数据。
7013

被折叠的 条评论
为什么被折叠?



