现有的APP中有许多涉及到隐私信息的页面,在被截图后会出现“保护个人隐私”等字样的提示,我们也可做其他操作,现在我们来进行阐述。

一、截屏活动的获取

iOS中通过此方法对截图活动进行检测,一旦捕获到就执行你所选定的方法。takeScreenshotAction为自己定义的方法。

OC:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(takeScreenshotAction) name:UIApplicationUserDidTakeScreenshotNotification object:nil];
- (void)takeScreenshotAction {NSLog(@"截屏");
}

Swift:

NotificationCenter.default.addObserver(self, selector: #selector(ViewController.takeScreenshotAction), name: NSNotification.Name.UIApplicationUserDidTakeScreenshot, object:nil)

二、拓展

截屏后,弹出请保护个人隐私的弹窗,一定时间后消失

方法一:添加动画,使label在指定时间内消失

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];label.center = self.view.center;label.backgroundColor = [UIColor grayColor];label.text = @"请注意保护个人隐私";label.textColor = [UIColor whiteColor];label.textAlignment = NSTextAlignmentCenter;[self.view addSubview:label];[UIView animateWithDuration:0.2 //动画时间delay:2.0 //开始延迟时间options:UIViewAnimationOptionCurveEaseInOut //弹入弹出animations:^{label.alpha = 0;} completion:^(BOOL finished) {label.hidden = YES;}];

方法二:使用[self performSelector:<#(nonnull SEL)#> withObject:<#(nullable id)#> afterDelay:<#(NSTimeInterval)#>],到达指定时间,使其消失。为增加其美观性可以为其添加动画。

[self performSelector:@selector(hide) withObject:nil afterDelay:2.0];
- (void)hide {for (UIView *view in self.view.subviews) {if ([view isKindOfClass:UILabel.class]) {
//            [UIView animateWithDuration:0.2 //动画时间
//                                  delay:0 //开始延迟时间
//                                options:UIViewAnimationOptionCurveEaseInOut //弹入弹出
//                             animations:^{
//                view.alpha = 0;
//            } completion:^(BOOL finished) {
//                view.hidden = YES;
//            }];view.hidden = YES;}}
}

三、主要代码

#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];self.view.backgroundColor = [UIColor whiteColor];[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(takeScreenshotAction) name:UIApplicationUserDidTakeScreenshotNotification object:nil];
}- (void)takeScreenshotAction {NSLog(@"截屏");[self initUI];
}- (void)initUI {UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];label.center = self.view.center;label.backgroundColor = [UIColor grayColor];label.text = @"请注意保护个人隐私";label.textColor = [UIColor whiteColor];label.textAlignment = NSTextAlignmentCenter;[self.view addSubview:label];
//    [self performSelector:@selector(hide) withObject:nil afterDelay:2.0];[UIView animateWithDuration:0.2 //动画时间delay:2.0 //开始延迟时间options:UIViewAnimationOptionCurveEaseInOut //弹入弹出animations:^{label.alpha = 0;} completion:^(BOOL finished) {label.hidden = YES;}];
}- (void)hide {for (UIView *view in self.view.subviews) {if ([view isKindOfClass:UILabel.class]) {
//            [UIView animateWithDuration:0.2 //动画时间
//                                  delay:0 //开始延迟时间
//                                options:UIViewAnimationOptionCurveEaseInOut //弹入弹出
//                             animations:^{
//                view.alpha = 0;
//            } completion:^(BOOL finished) {
//                view.hidden = YES;
//            }];view.hidden = YES;}}
}

iOS学习—截屏/屏幕获取的监测相关推荐

  1. iOS开发-检测用户截屏 并获取所截图片

    微信可以检测到用户截屏行为(Home + Power),并在稍后点击附加功能按钮时询问用户是否要发送刚才截屏的图片,这个用户体验非常好.于是乎, 我也想着实现这个功能. 在iOS7之前, 如果用户截屏 ...

  2. ios 代码截屏模糊问题解决办法

    ios 代码截屏模糊问题解决办法 参考文章: (1)ios 代码截屏模糊问题解决办法 (2)https://www.cnblogs.com/gaoxiaoniu/p/5941284.html (3)h ...

  3. iOS_截屏_获取截屏图片

    iOS 截屏,并获取截屏图片 // 1.添加系统通知 [[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector( ...

  4. windows生成ios上架截屏的方法

    我们在做ios app上架的时候,需要5.5寸.6.5寸和ipad的屏幕快照. 但是这些设备的截图,需要使用mac电脑安装xcode的模拟器,才能一一截图,而且非常麻烦.假如用windows电脑开发, ...

  5. android悬浮球截屏,vivoX27怎么双击悬浮球截屏?获取屏幕截图依旧方便快速!

    在此前一段时间中,iphone手机有一项功能在抖音中非常的火爆,那就是双击iphone的小白点进行截图的功能,让你不再依赖于截屏快捷键或是实体快捷键也能进行轻松的截图. 而今天我们要说的,是vivoX ...

  6. iOS实现截屏并保存到相册

    写入相册需要导入的头文件: #import <AssetsLibrary/AssetsLibrary.h> ... 1. iOS7之后的截屏方法,返回view     UIView *vi ...

  7. ios android 截屏 分享,iOS 系统自带截屏分享

    分享一篇iOS系统自带截屏分享 使用方案 UIImage *image = [KJTools kj_shareWithHideBlock:^bool{ /// 隐藏不需要截图的区域 return YE ...

  8. iOS 防止截屏、录屏技术

    0x00 直接看图 看图演示,可防止截屏和录屏 可以开启或者关闭,是否允许截屏和录屏 0x01 代码 JHNonRecordableView *view1 = [[JHNonRecordableVie ...

  9. ios android 截屏 分享,iOS微信截屏分享

    1.需求:將截屏后的圖片分享至微信好友或朋友圈. 2.問題:1.圖片縮略圖太大無法分享:2.分享的圖片不夠清晰. 3.描述:微信分享是需要設置兩張圖:需分享圖的縮略圖(大小有限制)和需分享的圖(要求高 ...

最新文章

  1. 0x08 大数据分析,七层基本功
  2. 2019DTCC大会分享:分布式数据库全局读一致性
  3. uvm 形式验证_验证平台自动化篇之二:UVM Framework
  4. nginx 配置文件 linux,Linux-nginx.conf配置文件模板
  5. Mybatis笔记——Mybatis入门
  6. 印刷体是什么意思_家长晒出4年级小学霸课前笔记,字迹堪比“印刷体”,老师都羡慕...
  7. Python--发送邮件
  8. 竹节纱疵的成因及预防措施
  9. 微信小程序教程笔记3
  10. Leetcode之整数转罗马数字
  11. 华为2019软件精英挑战赛-CodeCraft-2019大佬开源代码集合
  12. JS实现星星评分系统
  13. 逻辑题练习-if-for-数组
  14. mac中idea使用createNewFile创建文件
  15. adb通过wifi连接真机
  16. Android 新手引导添加View的方法
  17. 好用的在线加密解密工具,亲测有用
  18. 教科书所忽略的运算放大电路的有效带宽你还并不熟悉的增益带宽积概念
  19. (自适应移动设备)最新响应式个人博客自媒体文章博客资讯类网站源码 织梦模板
  20. 从云码课堂出来拿12K,女生做Java也挺吃香

热门文章

  1. 建筑CAD基础设计【4】
  2. 十分钟开发物联网:智能加湿器(Wifi版)
  3. Android Activity生命周期 举例说明
  4. 新建的Maven项目里面没有.iml文件怎么办
  5. docker查看java资源_JDK11设置Docker容器资源感知
  6. 软件园系列报道下一站——武汉“光谷”软件园
  7. 【VMware+CentOS7+EwoMail】 connect to 127.0.0.1[127.0.0.1]:10024: Connection refused
  8. JDK9-17新特性
  9. 从事Linux运维工作需要学习什么技能?
  10. MSP430F149——定时器