欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

iOS 截屏监听

程序员文章站 2022-03-29 23:07:05
截屏监听苹果有提供方法,可以注册监听,当用户有截屏操作的时候会通知我们:1、注册:[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didTakeScreenshot:) name:UIApplicationUserDidTakeScreenshotNotification object:nil];2、回调:- (void)didTakeScreenshot:(NSNotification...

苹果有提供方法,可以注册监听,当用户有截屏操作的时候会通知我们:

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);

}

本文地址:https://blog.csdn.net/jiangziwei/article/details/112556356