customerServiceViewController.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // customerServiceViewController.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/6/26.
  6. //
  7. #import "customerServiceViewController.h"
  8. #import <Photos/Photos.h>
  9. @interface customerServiceViewController ()
  10. @end
  11. @implementation customerServiceViewController
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. // Do any additional setup after loading the view.
  15. [self.toolBar setHidden:YES];
  16. [self.navigationBar setHidden:YES];
  17. [self.navBarBGView setHidden:NO];
  18. self.view.backgroundColor = HWF5F7FAColor;
  19. [self.titleLabel setText:NSLocalizedString(@"my_set_no_connect_kefu",nil)];
  20. [self initBaseUIFun];
  21. }
  22. #pragma mark
  23. - (void)initBaseUIFun
  24. {
  25. UIImageView *bgImageView = [[UIImageView alloc] init];
  26. bgImageView.image = [UIImage imageNamed:@"mine_customer_service"];
  27. //bgImageView.backgroundColor = [UIColor redColor];
  28. bgImageView.userInteractionEnabled = YES;
  29. [self.view addSubview:bgImageView];
  30. [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  31. make.left.mas_equalTo(0);
  32. make.top.mas_equalTo(self.navBarBGView.mas_bottom).offset(0);
  33. make.right.mas_equalTo(0);
  34. make.bottom.mas_equalTo(0);
  35. }];
  36. //长按保存相片
  37. UIButton *tipLab = [[UIButton alloc] init];
  38. // gradient
  39. CAGradientLayer *gl = [CAGradientLayer layer];
  40. gl.frame = CGRectMake(0,0,172,48);
  41. gl.startPoint = CGPointMake(0.05, 0.63);
  42. gl.endPoint = CGPointMake(1, 0.5);
  43. gl.colors = @[(__bridge id)[UIColor hwColor:@"#E9B780"].CGColor, (__bridge id)[UIColor hwColor:@"#9A6B45"].CGColor];
  44. gl.locations = @[@(0), @(1.0f)];
  45. [tipLab.layer addSublayer:gl];
  46. tipLab.userInteractionEnabled = NO;
  47. [tipLab setTitle:@"长按保存图片" forState:UIControlStateNormal];
  48. [tipLab setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  49. tipLab.titleLabel.font = [UIFont boldSystemFontOfSize:14.0];
  50. //tipLab.text = @"长按保存图片";
  51. //tipLab.textAlignment = NSTextAlignmentCenter;
  52. //tipLab.font = [UIFont systemFontOfSize:14.0];
  53. //tipLab.textColor = [UIColor whiteColor];
  54. //tipLab.backgroundColor = [UIColor hwColor:@"#FFFFFF" alpha:0.2];
  55. [bgImageView addSubview:tipLab];
  56. tipLab.layer.cornerRadius = 24;
  57. tipLab.layer.masksToBounds = YES;
  58. [tipLab mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.width.mas_equalTo(172);
  60. make.height.mas_equalTo(48);
  61. make.centerX.mas_equalTo(0);
  62. make.bottom.mas_equalTo(-35);
  63. }];
  64. // 创建长按手势识别器
  65. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
  66. // 设置长按手势的最小按压时间
  67. longPress.minimumPressDuration = 2; // 2秒
  68. // 将手势识别器添加到视图上
  69. [bgImageView addGestureRecognizer:longPress];
  70. }
  71. - (void)longPress:(UILongPressGestureRecognizer *)gesture {
  72. if (gesture.state == UIGestureRecognizerStateBegan) {
  73. //NSLog(@"长按手势开始");
  74. UIImage *image = [UIImage imageNamed:@"mine_customer_service"];
  75. [self saveImage:image];
  76. }
  77. }
  78. - (void)saveImage:(UIImage *)image
  79. {
  80. //保存图片到【相机胶卷】
  81. /// 异步执行修改操作
  82. [[PHPhotoLibrary sharedPhotoLibrary]performChanges:^{
  83. [PHAssetChangeRequest creationRequestForAssetFromImage:image];
  84. } completionHandler:^(BOOL success, NSError * _Nullable error) {
  85. mainBlock(^{
  86. if (error) {
  87. //NSLog(@"%@",@"保存失败");
  88. [[iToast makeText:NSLocalizedString(@"common_save_fail",nil)] show];
  89. } else {
  90. //NSLog(@"%@",@"保存成功");
  91. [[iToast makeText:NSLocalizedString(@"common_save_suc",nil)] show];
  92. }
  93. });
  94. }];
  95. }
  96. @end