美文网首页iOS开发点滴iOS一点通iOS开发(OC)
iOS 禁止截屏(截屏时,隐藏其页面内容)

iOS 禁止截屏(截屏时,隐藏其页面内容)

作者: 肉肉要次肉 | 来源:发表于2022-10-14 10:22 被阅读0次

手机截屏是手机系统操作,app是无法阻止这个操作的。

那么为了防止app内容被截屏我们可以通过UITextfeild控件的secureTextEntry属性来实现截屏空白页面,其原理就是利用了开启安全文本输入属性,将需要隐藏的内容添加到UITextfeild的子视图上,就可以达到此效果。

但是此方法只能iOS13以上使用。

创建UITextField,设置secureTextEntry = yes,签代理UITextFieldDelegate


    self.textTF = [[UITextField alloc]initWithFrame:self.view.bounds];

    [self.view addSubview:self.textTF];

    self.textTF.backgroundColor = [UIColor whiteColor];

    self.textTF.secureTextEntry = yes;

    self.textTF.delegate=self;

//将想要隐藏的内容添加到UITextField的子视图上

    UIView*theView = self.textTF.subviews.firstObject;

    [self.view  addSubview:theView];

    self.proImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"proImg"]];

    [theView  addSubview:self.proImg];

    self.proImg.frame=CGRectMake(0,0,200,200);

    self.proImg.center = self.view.center;

#pragma mark - UITextFieldDelegate

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {

    return NO;

}

截图前效果:

截图

真机截图后效果:

相关文章

网友评论

    本文标题:iOS 禁止截屏(截屏时,隐藏其页面内容)

    本文链接:https://www.haomeiwen.com/subject/djvfzrtx.html