XYInviteFriendsController.m 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. //
  2. // XYInviteFriendsController.m
  3. // Starbuds
  4. //
  5. // Created by gy on 2020/5/20.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYInviteFriendsController.h"
  9. #import "XYLiveRoomShareView.h"
  10. #import "NewPagedFlowView.h"
  11. #import <SDWebImagePrefetcher.h>
  12. #import "SDImageCache.h"
  13. #import "CodeHandlerObject.h"
  14. #import "UIView+AZGradient.h"
  15. #import "UIView+Snapshot.h"
  16. #import "XYInviteFriendsHistoryController.h"
  17. @interface XYInviteFriendsController ()<NewPagedFlowViewDelegate, NewPagedFlowViewDataSource>
  18. @property (nonatomic, strong) XYLiveRoomShareView *liveRoomShareView;
  19. @property (nonatomic, strong) NSMutableArray *imageArray;
  20. @property (nonatomic, strong) NewPagedFlowView *pageFlowView;
  21. @end
  22. @implementation XYInviteFriendsController
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // Do any additional setup after loading the view.
  26. self.view.backgroundColor = [UIColor whiteColor];
  27. self.title = kLocalizedString(@"邀请好友");
  28. UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  29. [rightBtn setTitle:@"记录" forState:UIControlStateNormal];
  30. [rightBtn setTitleColor:[UIColor colorWithHexString:@"#303133" alpha:1] forState:UIControlStateNormal];
  31. rightBtn.titleLabel.font = [UIFont fontWithName:kPFSCFont size:16];
  32. [rightBtn addTarget:self action:@selector(rightBtnAction) forControlEvents:UIControlEventTouchUpInside];
  33. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
  34. [SVProgressHUD showWithStatus:nil];
  35. kWEAKSELF
  36. [[XYUserAPIManager new] getPosterImages:nil successHandler:^(ZYLResponseModel *responseModel) {
  37. [SVProgressHUD dismiss];
  38. [weakSelf setup:responseModel.data];
  39. } failureHandler:^(ZYLNetworkError *error) {
  40. [SVProgressHUD dismiss];
  41. [SVProgressHUD showInfoWithStatus:error.domain];
  42. }];
  43. }
  44. - (void)rightBtnAction{
  45. XYInviteFriendsHistoryController *vc = [[XYInviteFriendsHistoryController alloc] init];
  46. [self.navigationController pushViewController:vc animated:YES];
  47. }
  48. - (void)setup:(NSDictionary *)data{
  49. NSArray *list = data[@"list"];
  50. for (NSDictionary *dict in list) {
  51. XYLiveRoomVCInfo *info = [[XYLiveRoomVCInfo alloc] init];
  52. info.sharePic = dict[@"imageUrl"];
  53. info.shareSubTitle = dict[@"inviteCode"];
  54. info.shareUrl = dict[@"posterLink"];
  55. [self.imageArray addObject:info];
  56. }
  57. [self.view addSubview:self.liveRoomShareView];
  58. for (XYLiveRoomVCInfo *info in self.imageArray) {
  59. [[SDWebImagePrefetcher sharedImagePrefetcher] prefetchURLs:@[[NSURL URLWithString:info.sharePic]] progress:^(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls) {
  60. } completed:^(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls) {
  61. }];
  62. }
  63. NewPagedFlowView *pageFlowView = [[NewPagedFlowView alloc] initWithFrame:CGRectMake(0, 72+kiPhoneXTopEdge, kScreenWidth, kScreenHeight-72-kiPhoneXTopEdge-152-kiPhoneXBottomEdge)];
  64. self.pageFlowView = pageFlowView;
  65. pageFlowView.delegate = self;
  66. pageFlowView.dataSource = self;
  67. pageFlowView.minimumPageAlpha = 0.1;
  68. pageFlowView.leftRightMargin = 35;
  69. pageFlowView.topBottomMargin = 55;
  70. pageFlowView.isCarousel = YES;
  71. pageFlowView.orientation = NewPagedFlowViewOrientationHorizontal;
  72. pageFlowView.isOpenAutoScroll = NO;
  73. //初始化pageControl
  74. UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, pageFlowView.f_y + pageFlowView.f_heigh + 18, kScreenWidth, 8)];
  75. pageControl.pageIndicatorTintColor = [UIColor colorWithHexString:@"#EFEFEF"alpha:1];
  76. pageControl.currentPageIndicatorTintColor = [UIColor colorWithHexString:@"#FF4D5C"alpha:1];
  77. pageFlowView.pageControl = pageControl;
  78. [self.view addSubview:pageControl];
  79. [pageFlowView reloadData];
  80. if (self.imageArray.count > 1) {
  81. [pageFlowView scrollToPage:self.imageArray.count/2];
  82. }
  83. [self shareCodeImg:(int )self.imageArray.count/2];
  84. [self.view addSubview:pageFlowView];
  85. }
  86. - (XYLiveRoomShareView *)liveRoomShareView{
  87. if (_liveRoomShareView == nil) {
  88. _liveRoomShareView = [[XYLiveRoomShareView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
  89. [self.view addSubview:_liveRoomShareView];
  90. [_liveRoomShareView setup:2];
  91. }
  92. return _liveRoomShareView;
  93. }
  94. #pragma mark NewPagedFlowView Delegate
  95. - (CGSize)sizeForPageInFlowView:(NewPagedFlowView *)flowView {
  96. return CGSizeMake(self.pageFlowView.f_width-62*2, self.pageFlowView.f_heigh);
  97. }
  98. - (void)didSelectCell:(UIView *)subView withSubViewIndex:(NSInteger)subIndex {
  99. NSLog(@"点击了第%ld张图",(long)subIndex + 1);
  100. }
  101. - (void)didScrollToPage:(NSInteger)pageNumber inFlowView:(NewPagedFlowView *)flowView {
  102. NSLog(@"ViewController 滚动到了第%ld页",pageNumber);
  103. [self shareCodeImg:(int )pageNumber];
  104. }
  105. #pragma mark NewPagedFlowView Datasource
  106. - (NSInteger)numberOfPagesInFlowView:(NewPagedFlowView *)flowView {
  107. return self.imageArray.count;
  108. }
  109. - (PGIndexBannerSubiew *)flowView:(NewPagedFlowView *)flowView cellForPageAtIndex:(NSInteger)index{
  110. PGIndexBannerSubiew *bannerView = [flowView dequeueReusableCell];
  111. if (!bannerView) {
  112. bannerView = [[PGIndexBannerSubiew alloc] init];
  113. bannerView.tag = index;
  114. bannerView.layer.cornerRadius = 4;
  115. bannerView.layer.masksToBounds = YES;
  116. }
  117. XYLiveRoomVCInfo *info = self.imageArray[index];
  118. [bannerView.mainImageView sd_setImageWithURL:[NSURL URLWithString:info.sharePic] placeholderImage:placeholderImage()];
  119. NSString *path = info.shareUrl;
  120. UIImage *image = [CodeHandlerObject createCodeWithUrl:path withSize:104];
  121. bannerView.codeImgView.image = image;
  122. bannerView.userIdLab.text = [NSString stringWithFormat:@"%@%@",kLocalizedString(@"邀请码:"),info.shareSubTitle];
  123. //bannerView.mainImageView.image = self.imageArray[index];
  124. return bannerView;
  125. }
  126. - (NSMutableArray *)imageArray {
  127. if (_imageArray == nil) {
  128. _imageArray = [NSMutableArray array];
  129. }
  130. return _imageArray;
  131. }
  132. - (void)shareCodeImg:(int )index{
  133. XYLiveRoomVCInfo *info = self.imageArray[index];
  134. if (!info.sharePic.length) { return; }
  135. self.liveRoomShareView.liveRoomVCInfo = info;
  136. NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:[NSURL URLWithString:info.sharePic]];
  137. UIImage *image = [[SDImageCache sharedImageCache] imageFromCacheForKey:key];
  138. UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
  139. bgImageView.contentMode = UIViewContentModeScaleAspectFill;
  140. UIImageView *codeImageView = [[UIImageView alloc] initWithFrame:CGRectMake((kScreenWidth-104)/2.0, kScreenHeight-44-104, 104, 104)];
  141. NSString *path = info.shareUrl;
  142. codeImageView.image = [CodeHandlerObject createCodeWithUrl:path withSize:codeImageView.f_heigh];
  143. [bgImageView addSubview:codeImageView];
  144. kViewRadius(codeImageView, 4);
  145. UILabel *userIdLab = [[UILabel alloc] initWithFrame: CGRectMake((kScreenWidth-124)/2.0, codeImageView.f_y+codeImageView.f_heigh+8, 124, 20)];
  146. userIdLab.textColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1];
  147. userIdLab.font = [UIFont fontWithName:kPFSCMediumFont size:12];
  148. userIdLab.textAlignment = NSTextAlignmentCenter;
  149. [userIdLab az_setGradientBackgroundWithColors:@[ColorFromHexString(@"#5D26FF"), ColorFromHexString(@"#9059FF")] locations:nil startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
  150. kViewRadius(userIdLab, 10);
  151. userIdLab.text = [NSString stringWithFormat:@"%@%@",kLocalizedString(@"邀请码:"),info.shareSubTitle];
  152. [bgImageView addSubview:userIdLab];
  153. if (image) {
  154. bgImageView.image = image;
  155. self.liveRoomShareView.liveRoomVCInfo.shareImageView = bgImageView;
  156. }else{
  157. kWEAKSELF
  158. [[SDWebImagePrefetcher sharedImagePrefetcher] prefetchURLs:@[[NSURL URLWithString:info.sharePic]] progress:^(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls) {
  159. } completed:^(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls) {
  160. NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:[NSURL URLWithString:info.sharePic]];
  161. bgImageView.image = [[SDImageCache sharedImageCache] imageFromCacheForKey:key];
  162. weakSelf.liveRoomShareView.liveRoomVCInfo.shareImageView = bgImageView;
  163. }];
  164. }
  165. }
  166. /*
  167. #pragma mark - Navigation
  168. // In a storyboard-based application, you will often want to do a little preparation before navigation
  169. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  170. // Get the new view controller using [segue destinationViewController].
  171. // Pass the selected object to the new view controller.
  172. }
  173. */
  174. @end