123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- //
- // forgetSecretKeyViewController.m
- // 隐私保护
- //
- // Created by xd h on 2023/11/7.
- //
- #import "forgetSecretKeyViewController.h"
- #import <Photos/Photos.h>
- @interface forgetSecretKeyViewController ()
- @end
- @implementation forgetSecretKeyViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- [self.toolBar setHidden:YES];
- [self.navigationBar setHidden:YES];
- [self.navBarBGView setHidden:NO];
- self.view.backgroundColor = HWF5F7FAColor;
-
- [self initBaseUIFun];
- }
- #pragma mark
- - (void)initBaseUIFun
- {
- UIImageView *bgImageView = [[UIImageView alloc] init];
- bgImageView.image = [UIImage imageNamed:@"gongzhonghao"];
- //bgImageView.backgroundColor = [UIColor redColor];
- bgImageView.userInteractionEnabled = YES;
- [self.view addSubview:bgImageView];
-
- [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(0);
- make.top.mas_equalTo(self.navBarBGView.mas_bottom).offset(0);
- make.right.mas_equalTo(0);
- make.bottom.mas_equalTo(0);
- }];
-
- //长按保存相片
- UILabel *tipLab = [[UILabel alloc] init];
- tipLab.text = @"长按保存图片";
- tipLab.textAlignment = NSTextAlignmentCenter;
- tipLab.font = [UIFont systemFontOfSize:14.0];
- tipLab.textColor = [UIColor whiteColor];
- tipLab.backgroundColor = [UIColor hwColor:@"#FFFFFF" alpha:0.2];
- [bgImageView addSubview:tipLab];
- tipLab.layer.cornerRadius = 24;
- tipLab.layer.masksToBounds = YES;
-
- [tipLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(140);
- make.height.mas_equalTo(48);
- make.centerX.mas_equalTo(0);
- make.bottom.mas_equalTo(-35);
- }];
-
- // 创建长按手势识别器
- UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
-
- // 设置长按手势的最小按压时间
- longPress.minimumPressDuration = 2; // 2秒
-
- // 将手势识别器添加到视图上
- [bgImageView addGestureRecognizer:longPress];
- }
- - (void)longPress:(UILongPressGestureRecognizer *)gesture {
- if (gesture.state == UIGestureRecognizerStateBegan) {
- //NSLog(@"长按手势开始");
-
- UIImage *image = [UIImage imageNamed:@"gongzhonghao"];
-
- [self saveImage:image];
-
- }
- }
- - (void)saveImage:(UIImage *)image
- {
- //保存图片到【相机胶卷】
- /// 异步执行修改操作
- [[PHPhotoLibrary sharedPhotoLibrary]performChanges:^{
- [PHAssetChangeRequest creationRequestForAssetFromImage:image];
- } completionHandler:^(BOOL success, NSError * _Nullable error) {
- mainBlock(^{
- if (error) {
- //NSLog(@"%@",@"保存失败");
- [[iToast makeText:NSLocalizedString(@"common_save_fail",nil)] show];
- } else {
- //NSLog(@"%@",@"保存成功");
- [[iToast makeText:NSLocalizedString(@"common_save_suc",nil)] show];
- }
- });
-
- }];
- }
- @end
|