MyQRCodeVC.m 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // MyQRCodeVC.m
  3. // smartRhino
  4. //
  5. // Created by armin on 2019/11/1.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "MyQRCodeVC.h"
  9. #import <Photos/Photos.h>
  10. #import "CreateNoteBookVC.h"
  11. @interface MyQRCodeVC ()
  12. @property (strong,nonatomic) IBOutlet UIView *showContentBgView;
  13. @property (strong,nonatomic) IBOutlet UIButton *shareBtn;
  14. @property (strong,nonatomic) IBOutlet UIImageView *qrCodeImg;
  15. @end
  16. @implementation MyQRCodeVC
  17. +(MyQRCodeVC *)initMyQRCodeVC{
  18. MyQRCodeVC *controller = [StoryboardManager.shared.myCenter instantiateViewControllerWithIdentifier:@"MyQRCodeVC"];
  19. return controller;
  20. }
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. self.fd_prefersNavigationBarHidden = YES;
  24. self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3f];
  25. UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)];
  26. self.view.userInteractionEnabled = YES;
  27. [gr setNumberOfTapsRequired:1];
  28. [self.view addGestureRecognizer:gr];
  29. self.showContentBgView.layer.masksToBounds = YES;
  30. self.showContentBgView.layer.cornerRadius = 5.0;
  31. UILongPressGestureRecognizer *longPressGesture =[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(headerLongPress:)];
  32. [self.showContentBgView addGestureRecognizer:longPressGesture];
  33. WS(weakSelf);
  34. [self.qrCodeImg setImageWithURL:[NSURL URLWithString:[AppUserModel sharedAppUserModel].QRCoder] placeholder:IMG(@"zhujun")];
  35. [self.shareBtn setAction:^{
  36. if (weakSelf.ClickShareBlock && weakSelf.qrCodeImg.image) {
  37. weakSelf.ClickShareBlock(weakSelf.qrCodeImg.image);
  38. [weakSelf dismiss];
  39. }
  40. }];
  41. }
  42. - (void)dismiss
  43. {
  44. self.view.hidden = YES;
  45. }
  46. /**
  47. * 长按
  48. */
  49. -(void)headerLongPress:(UILongPressGestureRecognizer *)longRecognizer{
  50. if (longRecognizer.state == UIGestureRecognizerStateBegan) {
  51. WS(weakSelf);
  52. NSError *error = nil;
  53. [[PHPhotoLibrary sharedPhotoLibrary] performChangesAndWait:^{
  54. [PHAssetChangeRequest creationRequestForAssetFromImage:weakSelf.qrCodeImg.image];
  55. } error:&error];
  56. if(error){
  57. [ShowtipTool showMessageWithStatus:@"保存失败"];
  58. }else{
  59. [ShowtipTool showMessageWithStatus:@"保存成功"];
  60. }
  61. }
  62. }
  63. @end