XYLiveRoomShareView.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. //
  2. // XYLiveRoomShareView.m
  3. // Starbuds
  4. //
  5. // Created by pajia on 2020/1/14.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYLiveRoomShareView.h"
  9. #import "XYSocialShareHandler.h"
  10. #import <SDWebImagePrefetcher.h>
  11. #import "SDImageCache.h"
  12. #import "UIImage+Save.h"
  13. #import "UIView+Snapshot.h"
  14. @interface XYLiveRoomShareViewItemView : BaseView
  15. @property (nonatomic, strong) UIImageView *imgView;
  16. @property (nonatomic, strong) UILabel *disLab;;
  17. - (void)setup;
  18. - (void)reload:(NSDictionary *)dataDict andSelect:(BOOL )select;
  19. @end
  20. @implementation XYLiveRoomShareViewItemView
  21. - (void)setup{
  22. self.backgroundColor = [UIColor clearColor];
  23. _imgView = [[UIImageView alloc] init];
  24. _imgView.contentMode = UIViewContentModeScaleAspectFill;
  25. [self addSubview:_imgView];
  26. [_imgView mas_makeConstraints:^(MASConstraintMaker *make) {
  27. make.top.equalTo(self.mas_top).offset(0);
  28. make.left.equalTo(self.mas_left).offset(0);
  29. make.width.offset(53);
  30. make.height.offset(53);
  31. }];
  32. [_imgView layoutIfNeeded];
  33. _disLab = [[UILabel alloc] init];
  34. _disLab.font = [UIFont fontWithName:kPFSCFont size:12];
  35. _disLab.textColor = [UIColor colorWithHexString:@"#FAFBFC" alpha:0.5];
  36. _disLab.text = @"-";
  37. [_disLab sizeToFit];
  38. [self addSubview:_disLab];
  39. [_disLab mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.top.equalTo(_imgView.mas_bottom).offset(8);
  41. make.centerX.equalTo(_imgView.mas_centerX).offset(0);
  42. }];
  43. [_disLab layoutIfNeeded];
  44. }
  45. - (void)reload:(NSDictionary *)dataDict andSelect:(BOOL )select{
  46. _imgView.image = [UIImage imageNamed:dataDict[@"image"]];
  47. _disLab.text = dataDict[@"dis"];
  48. }
  49. @end
  50. @interface XYLiveRoomShareView(){
  51. }
  52. @property (nonatomic, readwrite, strong) UIView *tapView;
  53. @property (nonatomic, readwrite, strong) UIView *shadowView;
  54. @property (nonatomic, readwrite, strong) NSMutableArray *dataArrs;
  55. @property (nonatomic, readwrite, strong) NSMutableArray *viewArrs;
  56. @property (nonatomic, readwrite, strong) UILabel *titleLab;
  57. @property (nonatomic, readwrite, strong) UIImageView *shareImgView;
  58. @property (nonatomic, readwrite, assign) int type;
  59. @end
  60. @implementation XYLiveRoomShareView
  61. - (void)setup:(int )type{
  62. self.type = type;
  63. self.tapView.hidden = YES;
  64. self.hidden = YES;
  65. self.backgroundColor = [UIColor clearColor];
  66. _dataArrs = [[NSMutableArray alloc] init];
  67. ///是否安装微信
  68. if ([XYSocialRegisterHandler isWXAppInstalled] && StringIsNotEmpty([XYAppConfigOauthsModel getOauthsModelWithType:XY_Login_type_WX_Login])) {
  69. if (type == 1) {
  70. [_dataArrs addObject:@{@"image":@"xy-lr-icon-share1",@"dis":kLocalizedString(@"微信好友")}];
  71. [_dataArrs addObject:@{@"image":@"xy-lr-icon-share2",@"dis":kLocalizedString(@"朋友圈")}];
  72. }else if (type == 2){
  73. [_dataArrs addObject:@{@"image":@"icon_invitefriendposter_wweixin",@"dis":kLocalizedString(@"微信好友")}];
  74. [_dataArrs addObject:@{@"image":@"icon_invitefriendposter_frirendcircle",@"dis":kLocalizedString(@"朋友圈")}];
  75. }
  76. }
  77. ///是否安装QQ
  78. if ([XYSocialRegisterHandler isQQAppInstalled] && StringIsNotEmpty([XYAppConfigOauthsModel getOauthsModelWithType:XY_Login_type_QQ_Login])) {
  79. if (type == 1) {
  80. [_dataArrs addObject:@{@"image":@"xy-lr-icon-share4",@"dis":kLocalizedString(@"QQ好友")}];
  81. }else if (type == 2){
  82. [_dataArrs addObject:@{@"image":@"icon_invitefriendposter_qq",@"dis":kLocalizedString(@"QQ好友")}];
  83. }
  84. }
  85. // 是否安装微博
  86. if ([XYSocialRegisterHandler isSinaAppInstalled] && StringIsNotEmpty([XYAppConfigOauthsModel getOauthsModelWithType:XY_Login_type_Sina_Login])) {
  87. if (type == 1) {
  88. [_dataArrs addObject:@{@"image":@"xy-lr-icon-share3",@"dis":kLocalizedString(@"微博")}];
  89. }else if (type == 2){
  90. [_dataArrs addObject:@{@"image":@"icon_invitefriendposter_weibo",@"dis":kLocalizedString(@"微博")}];
  91. }
  92. }
  93. if (type == 1) {
  94. [_dataArrs addObject:@{@"image":@"xy-lr-icon-share5",@"dis":kLocalizedString(@"复制链接")}];
  95. }else if (type == 2){
  96. [_dataArrs addObject:@{@"image":@"icon_invitefriendposter_saveimage",@"dis":kLocalizedString(@"保存图片")}];
  97. }
  98. _viewArrs = [[NSMutableArray alloc] init];
  99. _tapView = [[UIView alloc] init];
  100. _tapView.backgroundColor = [UIColor clearColor];
  101. [self addSubview:_tapView];
  102. _tapView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
  103. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapViewAction)];
  104. _tapView.userInteractionEnabled = YES;
  105. [_tapView addGestureRecognizer:tap];
  106. _shadowView = [[UIView alloc] init];
  107. _shadowView.backgroundColor = [UIColor colorWithHexString:@"#15061A" alpha:0.8];
  108. [self addSubview:_shadowView];
  109. _shadowView.frame = CGRectMake(0, kScreenHeight, kScreenWidth, 155+kiPhoneXBottomEdge);
  110. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, _shadowView.f_width, _shadowView.f_heigh) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(16, 16)];
  111. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  112. maskLayer.frame = CGRectMake(0, 0, _shadowView.f_width, _shadowView.f_heigh);
  113. maskLayer.path = maskPath.CGPath;
  114. _shadowView.layer.mask = maskLayer;
  115. UILabel *titleLab = [[UILabel alloc] init];
  116. self.titleLab = titleLab;
  117. titleLab.font = [UIFont fontWithName:kPFSCMediumFont size:16];
  118. titleLab.textColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:2];
  119. titleLab.text = kLocalizedString(@"分享给小伙伴,帮主播加油");
  120. [titleLab sizeToFit];
  121. [_shadowView addSubview:titleLab];
  122. [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  123. make.top.equalTo(_shadowView.mas_top).offset(20);
  124. make.centerX.equalTo(_shadowView.mas_centerX).offset(0);
  125. }];
  126. [titleLab layoutIfNeeded];
  127. UITapGestureRecognizer *titleLabtap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(titleLabAction)];
  128. //titleLabtap.numberOfTouchesRequired = 2;
  129. titleLabtap.numberOfTapsRequired = 5;
  130. titleLab.userInteractionEnabled = YES;
  131. [titleLab addGestureRecognizer:titleLabtap];
  132. _shareImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
  133. [_shareImgView sd_setImageWithURL:[NSURL URLWithString:self.liveRoomVCInfo.sharePic] placeholderImage:placeholderImage()];
  134. _shareImgView.hidden = YES;
  135. [_shadowView addSubview:_shareImgView];
  136. float itemWidth = 53;
  137. float itemHeight = 76;
  138. float itemEdge = 20;
  139. UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake((kScreenWidth-(itemWidth*self.dataArrs.count+itemEdge*(self.dataArrs.count-1)))/2.0, 62, itemWidth*self.dataArrs.count+itemEdge*(self.dataArrs.count-1), _shadowView.f_heigh-62)];
  140. contentView.backgroundColor = [UIColor clearColor];
  141. [_shadowView addSubview:contentView];
  142. for (int i = 0; i < self.dataArrs.count ; i++) {
  143. XYLiveRoomShareViewItemView *itemView = [[XYLiveRoomShareViewItemView alloc] init];
  144. [itemView setup];
  145. if (type == 2) {
  146. itemView.disLab.font = [UIFont fontWithName:kPFSCFont size:12];
  147. itemView.disLab.textColor = [UIColor colorWithHexString:@"#909399" alpha:1];
  148. }
  149. itemView.frame = CGRectMake(i*itemEdge+i*itemWidth, 0, itemWidth, itemHeight);
  150. itemView.tag = i;
  151. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(itemViewAction:)];
  152. itemView.userInteractionEnabled = YES;
  153. [itemView addGestureRecognizer:tap];
  154. [contentView addSubview:itemView];
  155. [self.viewArrs addObject:itemView];
  156. [itemView reload:_dataArrs[i] andSelect:NO];
  157. }
  158. if (type == 2) {
  159. UILabel *lineLab = [[UILabel alloc] init];
  160. lineLab.backgroundColor = [UIColor colorWithHexString:@"#DDDFE7" alpha:0.5];
  161. [lineLab sizeToFit];
  162. [_shadowView insertSubview:lineLab atIndex:0];
  163. [lineLab mas_makeConstraints:^(MASConstraintMaker *make) {
  164. make.left.equalTo(_shadowView.mas_left).offset(30);
  165. make.right.equalTo(_shadowView.mas_right).offset(-30);
  166. make.centerY.equalTo(titleLab.mas_centerY).offset(0);
  167. make.height.offset(1);
  168. }];
  169. [lineLab layoutIfNeeded];
  170. self.shadowView.backgroundColor = [UIColor whiteColor];
  171. self.titleLab.text = kLocalizedString(@" 分享到 ");
  172. self.titleLab.font = [UIFont fontWithName:kPFSCFont size:11];
  173. self.titleLab.textColor = [UIColor colorWithHexString:@"#606266" alpha:1];
  174. self.titleLab.backgroundColor = [UIColor colorWithHexString:@"#ffffff" alpha:1];
  175. self.tapView.hidden = YES;
  176. self.hidden = NO;
  177. self.shadowView.frame = CGRectMake(0, kScreenHeight-self.shadowView.f_heigh, kScreenWidth, self.shadowView.f_heigh);
  178. [titleLab mas_remakeConstraints:^(MASConstraintMaker *make) {
  179. make.top.equalTo(_shadowView.mas_top).offset(40);
  180. make.centerX.equalTo(_shadowView.mas_centerX).offset(0);
  181. }];
  182. }
  183. }
  184. - (void)titleLabAction{
  185. [XYLiveManger shareInstance].HDWindowLoggerShow = ![XYLiveManger shareInstance].HDWindowLoggerShow;
  186. if ([XYLiveManger shareInstance].HDWindowLoggerShow) {
  187. [SVProgressHUD showInfoWithStatus:@"show"];
  188. [[NSUserDefaults standardUserDefaults] setObject:@"HDWindowLoggerShow" forKey:@"HDWindowLoggerShow"];
  189. }else{
  190. [SVProgressHUD showInfoWithStatus:@"hide"];
  191. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"HDWindowLoggerShow"];
  192. }
  193. }
  194. - (void)setLiveRoomVCInfo:(XYLiveRoomVCInfo *)liveRoomVCInfo{
  195. _liveRoomVCInfo = liveRoomVCInfo;
  196. if (!liveRoomVCInfo.shareUrl.length) {
  197. return;
  198. }
  199. // [_shareImgView sd_setImageWithURL:[NSURL URLWithString:self.liveRoomVCInfo.sharePic] placeholderImage:placeholderImage()];
  200. [[SDWebImagePrefetcher sharedImagePrefetcher] prefetchURLs:@[[NSURL URLWithString:self.liveRoomVCInfo.sharePic]] progress:^(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls) {
  201. } completed:^(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls) {
  202. }];
  203. // SDWebImageManager *manager = [SDWebImageManager sharedManager] ;
  204. // [manager downloadImageWithURL:[NSURL URLWithString:self.liveRoomVCInfo.sharePic] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
  205. // // progression tracking code
  206. // } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
  207. // if (image) {
  208. // self.shareImgView.image = image;
  209. // }
  210. // }];
  211. }
  212. - (void)show{
  213. self.tapView.hidden = NO;
  214. self.hidden = NO;
  215. kWEAKSELF
  216. [UIView animateWithDuration:0.3 animations:^{
  217. weakSelf.shadowView.frame = CGRectMake(0, kScreenHeight-weakSelf.shadowView.f_heigh, kScreenWidth, weakSelf.shadowView.f_heigh);
  218. } completion:^(BOOL finished) {
  219. }];
  220. }
  221. - (void)tapViewAction{
  222. kWEAKSELF
  223. [UIView animateWithDuration:0.3 animations:^{
  224. weakSelf.shadowView.frame = CGRectMake(0, kScreenHeight, kScreenWidth, weakSelf.shadowView.f_heigh);
  225. } completion:^(BOOL finished) {
  226. weakSelf.tapView.hidden = YES;
  227. weakSelf.hidden = YES;
  228. }];
  229. }
  230. - (void)itemViewAction:(UITapGestureRecognizer *)tapges{
  231. UIImage *image1;
  232. UIImage *image2;
  233. if (self.type == 1) {
  234. NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:[NSURL URLWithString:self.liveRoomVCInfo.sharePic]];
  235. image1 = [[SDImageCache sharedImageCache] imageFromCacheForKey:key];
  236. }else if (self.type == 2){
  237. image2 = [self.liveRoomVCInfo.shareImageView snapshotImage];
  238. }
  239. //UIImage *image = self.shareImgView.image;
  240. UIView *view = [tapges view];
  241. NSInteger tag = view.tag;
  242. NSString *name = self.dataArrs[tag][@"dis"];
  243. if ([name isEqualToString:kLocalizedString(@"微信好友")]) {//微信好友
  244. if (self.type == 1) {
  245. [[XYSocialShareHandler sharedInstance] share_WXURLWithTitle:self.liveRoomVCInfo.shareTitle description:self.liveRoomVCInfo.shareSubTitle thumbImage:image1 url:self.liveRoomVCInfo.shareUrl];
  246. }else if (self.type == 2){
  247. [[XYSocialShareHandler sharedInstance] share_WXImageWithImage:image2 thumbImage:image2];
  248. }
  249. }else if ([name isEqualToString:kLocalizedString(@"朋友圈")]){//朋友圈
  250. if (self.type == 1) {
  251. [[XYSocialShareHandler sharedInstance] share_PYQURLWithTitle:self.liveRoomVCInfo.shareTitle description:self.liveRoomVCInfo.shareSubTitle thumbImage:image1 url:self.liveRoomVCInfo.shareUrl];
  252. }else if (self.type == 2){
  253. [[XYSocialShareHandler sharedInstance] share_PYQImageWithImage:image2 thumbImage:image2];
  254. }
  255. }else if ([name isEqualToString:kLocalizedString(@"微博")]){//微博
  256. if (self.type == 1) {
  257. [[XYSocialShareHandler sharedInstance] share_sinaUrlWithUrl:self.liveRoomVCInfo.shareUrl title:self.liveRoomVCInfo.shareTitle description:self.liveRoomVCInfo.shareSubTitle thumbImage:image1];
  258. }else if (self.type == 2){
  259. [[XYSocialShareHandler sharedInstance] share_sinaImageWithImages:@[image2]];
  260. }
  261. }else if ([name isEqualToString:kLocalizedString(@"QQ好友")]){//qq好友
  262. if (self.type == 1) {
  263. [[XYSocialShareHandler sharedInstance] share_QQUrlWithUrl:self.liveRoomVCInfo.shareUrl title:self.liveRoomVCInfo.shareTitle description:self.liveRoomVCInfo.shareSubTitle previewImageURL:self.liveRoomVCInfo.sharePic shareType:1];
  264. }else if (self.type == 2){
  265. [[XYSocialShareHandler sharedInstance] share_QQImageWithImage:image2 title:@"" description:@"" shareType:1];
  266. }
  267. }else if ([name isEqualToString:kLocalizedString(@"复制链接")] || [name isEqualToString:kLocalizedString(@"保存图片")] ){//复制链接
  268. if (self.type == 1) {
  269. if (!self.liveRoomVCInfo.shareUrl.length) { return; }
  270. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  271. pasteboard.string = self.liveRoomVCInfo.shareUrl;
  272. [SVProgressHUD showSuccessWithStatus:kLocalizedString(@"已复制至剪切板")];
  273. }else if (self.type == 2){
  274. [image2 saveImageToPhotoAlbumWithImage:image2 completion:^(BOOL success, NSError * _Nullable error) {
  275. if (success) {
  276. [SVProgressHUD showSuccessWithStatus:kLocalizedString(@"已保存图片")];
  277. }
  278. }];
  279. }
  280. }
  281. }
  282. - (void)clear{
  283. }
  284. @end