iOS开发点滴iOS一点通iOS开发(OC)

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

2022-10-14  本文已影响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;

}

截图前效果:

截图

真机截图后效果:

上一篇 下一篇

猜你喜欢

热点阅读