BogoShareViewController.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // BogoShareViewController.m
  3. // UniversalApp
  4. //
  5. // Created by Mac on 2021/8/9.
  6. // Copyright © 2021 voidcat. All rights reserved.
  7. //
  8. #import "BogoShareViewController.h"
  9. #import <TYCyclePagerView/TYCyclePagerView.h>
  10. #import <TYCyclePagerView/TYPageControl.h>
  11. #import "TYCyclePagerViewCell.h"
  12. #import "CommonShareView.h"
  13. #import <SDWebImage/SDWebImage.h>
  14. #import "BogoNetworkKit.h"
  15. #import "BogoShopKit.h"
  16. @interface BogoShareBgModel : NSObject
  17. @property (nonatomic, assign) NSInteger addtime;
  18. @property (nonatomic, assign) NSInteger id;
  19. @property (nonatomic, copy) NSString *img;
  20. @property (nonatomic, assign) NSInteger sort;
  21. @property (nonatomic, assign) NSInteger status;
  22. @end
  23. @implementation BogoShareBgModel
  24. @end
  25. @interface BogoShareViewController ()<TYCyclePagerViewDataSource,TYCyclePagerViewDelegate,CommonShareViewDelegate>
  26. @property(nonatomic, strong) TYCyclePagerView *pageView;
  27. @property(nonatomic, strong) NSMutableArray *dataArray;
  28. @property(nonatomic, strong) CommonShareView *shareView;
  29. @property(nonatomic, assign) NSInteger currentIndex;
  30. @end
  31. @implementation BogoShareViewController
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. // Do any additional setup after loading the view.
  35. [self.view addSubview:self.pageView];
  36. [self.view addSubview:self.shareView];
  37. [self requesrData];
  38. }
  39. - (void)requesrData{
  40. // /mapi/index.php?ctl=invite_vue&act=share_bg&uid=166238
  41. [[BogoNetwork shareInstance] POSTV3:@"" param:@{@"ctl":@"invite_vue",@"act":@"share_bg"} success:^(BogoNetworkResponseModel * _Nonnull result) {
  42. for (NSDictionary *dict in result.data) {
  43. BogoShareBgModel *model = [BogoShareBgModel mj_objectWithKeyValues:dict];
  44. [self.dataArray addObject:model];
  45. }
  46. [self.pageView reloadData];
  47. } failure:^(NSString * _Nonnull error) {
  48. [[BGHUDHelper sharedInstance] tipMessage:error];
  49. }];
  50. }
  51. - (void)viewWillLayoutSubviews {
  52. [super viewWillLayoutSubviews];
  53. self.pageView.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), kScreenHeight - 133 - FD_Bottom_SafeArea_Height - kTopHeight);
  54. self.shareView.frame = CGRectMake(0, kScreenHeight - 133 - FD_Bottom_SafeArea_Height - kTopHeight, kScreenW, 133 + FD_Bottom_SafeArea_Height);
  55. }
  56. - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
  57. if (error) {
  58. [[BGHUDHelper sharedInstance] tipMessage:error.localizedDescription];
  59. }else{
  60. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"保存图片成功")];
  61. }
  62. }
  63. #pragma mark - CommonShareViewDelegate
  64. - (void)shareView:(CommonShareView *)shareView didClickBtn:(QMUIButton *)sender{
  65. switch (sender.tag - kRoomShareViewBaseBtnTag) {
  66. case UMSocialPlatformType_UnKnown:
  67. //保存图片
  68. {
  69. TYCyclePagerViewCell *cell = (TYCyclePagerViewCell *)[self.pageView curIndexCell];
  70. UIImage *image = [cell convertViewToImage];
  71. if (image) {
  72. UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
  73. }
  74. }
  75. break;
  76. default:
  77. {
  78. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  79. UMShareImageObject *imageObject = [[UMShareImageObject alloc]init];
  80. TYCyclePagerViewCell *cell = (TYCyclePagerViewCell *)[self.pageView curIndexCell];
  81. // if (sender.tag - kRoomShareViewBaseBtnTag == UMSocialPlatformType_WechatSession ||sender.tag - kRoomShareViewBaseBtnTag == UMSocialPlatformType_WechatTimeLine) {
  82. // if (![WXApi isWXAppInstalled]) {
  83. // [[BGHUDHelper sharedInstance] tipMessage:@"未安装微信"];
  84. // return;
  85. // }
  86. // }
  87. UIImage *image = [cell convertViewToImage];
  88. imageObject.shareImage = image;
  89. messageObject.shareObject = imageObject;
  90. [[UMSocialManager defaultManager] shareToPlatform:sender.tag - kRoomShareViewBaseBtnTag messageObject:messageObject currentViewController:self completion:^(id result, NSError *error) {
  91. if (error) {
  92. [[BGHUDHelper sharedInstance] tipMessage:@"当前分享方式不可用,请使用其他方式分享"];
  93. }else{
  94. [[BGHUDHelper sharedInstance] tipMessage:NSLocalizedString(@"分享成功",nil)];
  95. }
  96. }];
  97. }
  98. break;
  99. }
  100. }
  101. #pragma mark - TYCyclePagerViewDataSource,TYCyclePagerViewDelegate
  102. - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView{
  103. return self.dataArray.count;
  104. }
  105. - (__kindof UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index{
  106. TYCyclePagerViewCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndex:index];
  107. if (index < self.dataArray.count) {
  108. BogoShareBgModel *model = self.dataArray[index];
  109. [cell.imageView sd_setImageWithURL:[NSURL URLWithString:model.img]];
  110. NSString *url = [NSString stringWithFormat:@"%@&invite_code=%@",[GlobalVariables sharedInstance].appModel.h5_url.download_url,[IMAPlatform sharedInstance].host.imUserId];
  111. cell.qrCode = url;
  112. }
  113. return cell;
  114. }
  115. - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
  116. TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
  117. layout.itemSize = CGSizeMake(CGRectGetWidth(pageView.frame) - 120, CGRectGetHeight(pageView.frame) - 80);
  118. layout.itemSpacing = 30;
  119. layout.layoutType = TYCyclePagerTransformLayoutLinear;
  120. return layout;
  121. }
  122. - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex{
  123. self.currentIndex = toIndex;
  124. }
  125. - (TYCyclePagerView *)pageView{
  126. if (!_pageView) {
  127. _pageView = [[TYCyclePagerView alloc]initWithFrame:CGRectZero];
  128. _pageView.layer.borderWidth = 0;
  129. _pageView.isInfiniteLoop = YES;
  130. _pageView.dataSource = self;
  131. _pageView.delegate = self;
  132. _pageView.collectionView.backgroundColor = [UIColor colorWithHexString:@"#F4F4F4"];
  133. [_pageView registerClass:[TYCyclePagerViewCell class] forCellWithReuseIdentifier:@"cellId"];
  134. }
  135. return _pageView;
  136. }
  137. - (CommonShareView *)shareView{
  138. if (!_shareView) {
  139. _shareView = [[CommonShareView alloc]initWithFrame:CGRectMake(0, kScreenHeight - 133 - FD_Bottom_SafeArea_Height - kTopHeight, kScreenW, 133 + FD_Bottom_SafeArea_Height)];
  140. _shareView.delegate = self;
  141. }
  142. return _shareView;
  143. }
  144. - (NSMutableArray *)dataArray{
  145. if (!_dataArray) {
  146. _dataArray = [NSMutableArray array];
  147. }
  148. return _dataArray;
  149. }
  150. @end