YOUPAILZShareApplicationWindow.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //
  2. // YOUPAILZShareApplicationWindow.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/9/28.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZShareApplicationWindow.h"
  9. #import <UMShare/UMShare.h>
  10. @interface YOUPAILZShareApplicationWindow ()
  11. @property (nonatomic,strong) UIImageView *youpaipbgV;
  12. @end
  13. @implementation YOUPAILZShareApplicationWindow
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. self.baseView.hidden = YES;
  17. [self youpaifinitUI];
  18. }
  19. - (void)youpaifinitUI{
  20. UIView *bgV = [[UIView alloc] init];
  21. bgV.layer.cornerRadius = ScaleSize(16.0f);
  22. bgV.clipsToBounds = YES;
  23. bgV.backgroundColor = LCBkgColor;
  24. [self.view addSubview:bgV];
  25. // self.youpaipbgV = bgV;
  26. [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  27. make.centerY.equalTo(self.view);
  28. make.centerX.equalTo(self.view);
  29. make.size.mas_offset(CGSizeMake(ScaleSize(280.0f), ScaleSize(492.0f)));
  30. }];
  31. UIImageView *imgV = [[UIImageView alloc] init];
  32. [imgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.youpaipmodel.youpaipposterPicUrl]];
  33. [bgV addSubview:imgV];
  34. self.youpaipbgV = imgV;
  35. [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.left.top.right.offset(0.0f);
  37. make.height.offset(ScaleSize(404.0f));
  38. }];
  39. UIView *qrcodeV = [[UIView alloc] init];
  40. qrcodeV.backgroundColor = [UIColor whiteColor];
  41. [imgV addSubview:qrcodeV];
  42. [qrcodeV mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.bottom.offset(-ScaleSize(20.0f));
  44. make.centerX.equalTo(imgV);
  45. make.size.mas_offset(CGSizeMake(ScaleSize(70.0f), ScaleSize(70.0f)));
  46. }];
  47. UIImageView *qrcodeImgV = [[UIImageView alloc] init];
  48. qrcodeImgV.image = [LCTools createQRCodeImageHaveCenterIMG:self.youpaipmodel.youpaipqCodeContent centerIMG:nil];
  49. [qrcodeV addSubview:qrcodeImgV];
  50. [qrcodeImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.left.top.offset(5.0f);
  52. make.bottom.right.offset(-5.0f);
  53. }];
  54. UIView *footerV = [[UIView alloc] init];
  55. footerV.backgroundColor = [UIColor whiteColor];
  56. [bgV addSubview:footerV];
  57. [footerV mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.left.bottom.right.offset(0.0f);
  59. make.top.equalTo(imgV.mas_bottom).offset(0.0f);
  60. }];
  61. NSArray *shareItems = @[
  62. @{@"image":@"vqu_images_share_weixin_timeline",@"title":@"朋友圈"},
  63. @{@"image":@"vqu_images_share_weixin",@"title":@"微信"},
  64. @{@"image":@"vqu_images_share_qq",@"title":@"QQ"},
  65. @{@"image":@"vqu_images_share_save_local",@"title":@"保存到相册"},
  66. ];
  67. NSMutableArray <UIButton *> *items = [NSMutableArray array];
  68. for (NSInteger i = 0; i < shareItems.count; i ++) {
  69. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  70. btn.tag = i;
  71. [btn addTarget:self action:@selector(youpaifItemClick:) forControlEvents:UIControlEventTouchUpInside];
  72. [footerV addSubview:btn];
  73. [items addObject:btn];
  74. NSDictionary *dict = shareItems[i];
  75. UIImageView *imgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:dict[@"image"]]];
  76. [btn addSubview:imgV];
  77. [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.top.offset(ScaleSize(8.0f));
  79. make.centerX.equalTo(btn);
  80. make.size.mas_offset(CGSizeMake(ScaleSize(37.0f), ScaleSize(37.0f)));
  81. }];
  82. UILabel *titleL = [[UILabel alloc] init];
  83. titleL.font = LCFont(ScaleSize(10.0f));
  84. titleL.textColor = HexColorFromRGB(0x333333);
  85. titleL.text = dict[@"title"];
  86. [btn addSubview:titleL];
  87. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.centerX.equalTo(btn);
  89. make.bottom.offset(-ScaleSize(8.0f));
  90. }];
  91. }
  92. [items mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:0.0f leadSpacing:ScaleSize(15.0f) tailSpacing:ScaleSize(15.0f)];
  93. [items mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.top.offset(ScaleSize(8.0f));
  95. make.bottom.offset(ScaleSize(-8.0f));
  96. }];
  97. }
  98. - (void)youpaifItemClick:(UIButton *)sender{
  99. UIImage *img = [self youpaifconvertViewToImage:self.youpaipbgV];
  100. NSInteger index = sender.tag;
  101. if (index == 0) {
  102. [self shareWithPlatform:UMSocialPlatformType_WechatTimeLine image:img];
  103. }else if (index == 1){
  104. [self shareWithPlatform:UMSocialPlatformType_WechatSession image:img];
  105. }else if (index == 2){
  106. [self shareWithPlatform:UMSocialPlatformType_QQ image:img];
  107. }else if (index == 3){
  108. [self youpaifsaveImage:img];
  109. }
  110. }
  111. - (void)shareWithPlatform:(UMSocialPlatformType)platformType image:(UIImage *)image{
  112. UMShareImageObject* imageObject = [[UMShareImageObject alloc]init];
  113. [imageObject setShareImage:image];
  114. UMSocialMessageObject *message = [[UMSocialMessageObject alloc] init];
  115. message.shareObject = imageObject;
  116. [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:message currentViewController:nil completion:^(id result, NSError *error) {
  117. if (error == nil) {
  118. [LCHttpHelper requestWithURLString:ShareTask parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  119. NSDictionary* dict = (NSDictionary*)responseObject;
  120. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  121. if (code==0) {//成功
  122. [[NSNotificationCenter defaultCenter]postNotificationName:@"yqApplePaySuccess" object:nil userInfo:nil];
  123. }
  124. } failure:^(NSError *error) {
  125. }];
  126. }
  127. }];
  128. }
  129. - (void)youpaifsaveImage:(UIImage *)image{
  130. [self dismissViewControllerAnimated:YES completion:^{
  131. [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
  132. [PHAssetChangeRequest creationRequestForAssetFromImage:image];
  133. } completionHandler:^(BOOL success, NSError * _Nullable error) {
  134. if (success) {
  135. [ZCHUDHelper showTitle:@"保存成功"];
  136. }else{
  137. [ZCHUDHelper showTitle:@"保存失败"];
  138. }
  139. }];
  140. }];
  141. }
  142. //使用该方法不会模糊,根据屏幕密度计算
  143. - (UIImage *)youpaifconvertViewToImage:(UIView *)view {
  144. [view.superview layoutIfNeeded];
  145. // view.layer.cornerRadius = 0.0f;
  146. UIImage *imageRet = [[UIImage alloc]init];
  147. // 传入的View.frame.size是0的话,直接返回nil,防止 UIGraphicsBeginImageContext() 传入0,导致崩溃
  148. if (CGSizeEqualToSize(view.frame.size, CGSizeZero)) {
  149. return nil;
  150. }
  151. //UIGraphicsBeginImageContextWithOptions(区域大小, 是否是非透明的, 屏幕密度);
  152. UIGraphicsBeginImageContextWithOptions(view.frame.size, YES, [UIScreen mainScreen].scale);
  153. [view.layer renderInContext:UIGraphicsGetCurrentContext()];
  154. imageRet = UIGraphicsGetImageFromCurrentImageContext();
  155. UIGraphicsEndImageContext();
  156. return imageRet;
  157. }
  158. @end