《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRInviteFansViewController.m 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. //
  2. // DRInviteFansViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/19.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRInviteFansViewController.h"
  9. #import "DRInviteBannerView.h"
  10. #import "shareView.h"
  11. #import "DRShareGetFriendsView.h"
  12. #import "DRPrivilegeReferralViewController.h"
  13. @interface DRInviteFansViewController ()<YHInviteBannerDelegate>
  14. @property(nonatomic,strong)UIView *backShareView;
  15. @property(nonatomic,strong)shareView *shareView;
  16. @property(nonatomic,strong)UILabel *inviteNumber;
  17. @property(nonatomic,strong)DRInviteBannerView *bannerView;
  18. @property(nonatomic,copy)NSString *inviteCode;
  19. @property(nonatomic,copy)NSString *shareUrl;
  20. @property(nonatomic,copy)NSString *headimg;
  21. @property(nonatomic,copy)NSString *nickName;
  22. @property(nonatomic) NSInteger selectIndex;//当前选中海报
  23. @end
  24. @implementation DRInviteFansViewController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. [self configNavigationBar];
  28. [self configUI];
  29. }
  30. -(void)viewWillAppear:(BOOL)animated{
  31. [super viewWillAppear:animated];
  32. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  33. [self request];
  34. }
  35. - (void)viewWillDisappear:(BOOL)animated {
  36. [super viewWillDisappear:animated];
  37. [SVProgressHUD dismiss];
  38. }
  39. - (void)configNavigationBar {
  40. [self.navigationBar setNavTitle:@"邀请好友"];
  41. self.navigationBar.backgroundColor = [UIColor changeColor];
  42. self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
  43. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  44. [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
  45. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  46. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  47. }
  48. - (void)backAction {
  49. [self.navigationController popViewControllerAnimated:YES];
  50. }
  51. -(void)request{
  52. [SVProgressHUD show];
  53. NSString *url=[NSString stringWithFormat:@"%@/api/v2/users/inviteFriends",BaseURL];
  54. [DRHttp post:url params:nil success:^(id json) {
  55. if (json) {
  56. NSArray *imgArr=json[@"imgs"];
  57. NSString *code=json[@"invite_code"];
  58. NSString *shareUrl=json[@"share_url"];
  59. self.inviteCode=[NSString stringWithFormat:@"%@",code];
  60. self.shareUrl=shareUrl;
  61. self.bannerView.dataArr=[NSArray arrayWithArray:imgArr];
  62. self.nickName = json[@"nickname"];
  63. self.headimg = json[@"headimg"];
  64. }
  65. [SVProgressHUD dismiss];
  66. } failure:^(NSError *error) {
  67. [SVProgressHUD dismiss];
  68. }];
  69. }
  70. - (void)configUI {
  71. self.view.backgroundColor = [UIColor whiteColor];
  72. UILabel *desLabel = [[UILabel alloc] initWithFrame:CGRectMake(28, NavBarHeight+Fitsize(31), SCREEN_WIDTH-56, 40)];
  73. desLabel.numberOfLines = 2;
  74. desLabel.text = @"分享专属海报,新用户注册后直接成为你的粉丝\n1.微信扫码下载->2.微信登录->3.成为你的粉丝";
  75. desLabel.font = [UIFont systemFontOfSize:14];
  76. desLabel.textColor = [UIColor YHColorWithHex:0x666666];
  77. desLabel.textAlignment = NSTextAlignmentCenter;
  78. [self.view addSubview:desLabel];
  79. DRInviteBannerView *bannerView = [[DRInviteBannerView alloc] initWithFrame:CGRectMake(0, desLabel.bottom+Fitsize(32), SCREEN_WIDTH, Fitsize(360))];
  80. bannerView.delegate=self;
  81. bannerView.layer.masksToBounds=YES;
  82. [self.view addSubview:bannerView];
  83. self.bannerView=bannerView;
  84. UILabel *inviteNumber = [[UILabel alloc] initWithFrame:CGRectMake(0, bannerView.bottom+Fitsize(34), 200, 20)];
  85. inviteNumber.textColor = [UIColor YHColorWithHex:0x333333];
  86. inviteNumber.font = [UIFont boldSystemFontOfSize:14];
  87. inviteNumber.text = @"我的邀请码:--------";
  88. [inviteNumber sizeToFit];
  89. [self.view addSubview:inviteNumber];
  90. self.inviteNumber=inviteNumber;
  91. inviteNumber.centerX = self.view.centerX;
  92. NSInteger offInt=0;
  93. if (iPhoneX) {
  94. offInt=50;
  95. }
  96. UIButton *shareLink = [[UIButton alloc] initWithFrame:CGRectMake(10, SCREEN_HEIGHT-Fitsize(55)-offInt, (self.view.width-30)/2, Fitsize(40))];
  97. [shareLink setTitle:@"复制邀请码" forState:UIControlStateNormal];
  98. shareLink.backgroundColor = [UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0xFEC800] toColor:[UIColor YHColorWithHex:0xFD9D03] withWidth:shareLink.width];
  99. shareLink.layer.cornerRadius = 4;
  100. shareLink.tag=10001;
  101. shareLink.titleLabel.font = [UIFont systemFontOfSize:Fitsize(16)];
  102. [shareLink addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
  103. [shareLink setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  104. [self.view addSubview:shareLink];
  105. UIButton *shareImg = [[UIButton alloc] initWithFrame:CGRectMake(shareLink.right+5, shareLink.top, (self.view.width-30)/2, Fitsize(40))];
  106. shareImg.tag=10002;
  107. shareImg.backgroundColor = [UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0xFE6735] toColor:[UIColor YHColorWithHex:0xFF2D23] withWidth:shareLink.width];
  108. [shareImg setTitle:@"分享专属海报" forState:UIControlStateNormal];
  109. [shareImg addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
  110. [shareImg setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  111. shareImg.layer.cornerRadius = 4;
  112. shareImg.titleLabel.font = [UIFont systemFontOfSize:Fitsize(16)];
  113. [self.view addSubview:shareImg];
  114. [[UIApplication sharedApplication].keyWindow addSubview:self.backShareView];
  115. [[UIApplication sharedApplication].keyWindow addSubview:self.shareView];
  116. }
  117. -(void)doTapChange{
  118. self.backShareView.hidden=YES;
  119. [UIView animateWithDuration:0.2f animations:^{
  120. self.shareView.frame=CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 200+SafeBottomHeight);
  121. } completion:^(BOOL finished) {
  122. }];
  123. }
  124. -(void)didCurrentCellAtIndex:(NSInteger)index{
  125. self.selectIndex=index;
  126. }
  127. -(void)shareAction:(UIButton *)sender{
  128. // if ([self.flag integerValue]==0 ||[self.flag integerValue]==1) {
  129. // UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"邀请好友" message:[NSString stringWithFormat:@"\n您还不是超级会员,升级到超级会员才能邀请好友"] preferredStyle:UIAlertControllerStyleAlert];
  130. // UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"去升级" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  131. // DRPrivilegeReferralViewController *vc=[[DRPrivilegeReferralViewController alloc]init];
  132. // [self.navigationController pushViewController:vc animated:YES];
  133. // }];
  134. // UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  135. // }];
  136. // [alert addAction:cancelAction];
  137. // [alert addAction:defaultAction];
  138. // [self presentViewController:alert animated:YES completion:nil];
  139. // return;
  140. // }else if([self.flag integerValue]==-1){
  141. // [MBProgressHUD showMessage:@"正在确认您的等级"];
  142. // }
  143. switch (sender.tag) {
  144. case 10001:
  145. {
  146. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  147. pasteboard.string =[NSString stringWithFormat:@"%@",self.inviteCode];
  148. [MBProgressHUD showTip:@"复制成功"];
  149. }
  150. break;
  151. case 10002:
  152. {
  153. self.backShareView.hidden=NO;
  154. DRShareGetFriendsView *imgView=[[DRShareGetFriendsView alloc]initWithFrame:CGRectMake(0, 0, 375, 667)];
  155. DRShareGetFriendsModel *model=[[DRShareGetFriendsModel alloc]init];
  156. model.getFriendCode=self.inviteCode;
  157. model.QRcodeUrl=self.shareUrl;
  158. model.imgUrl=self.bannerView.dataArr[self.selectIndex];
  159. model.inviteCode = self.inviteCode;
  160. model.headimg = self.headimg;
  161. model.nickname = self.nickName;
  162. self.shareView.imgUrl = model.imgUrl;
  163. __weak DRShareGetFriendsView *wkimgView=imgView;
  164. imgView.imgSuccBlock = ^{
  165. UIImage *img=[wkimgView changeToImage];
  166. [self.shareView shareImage:img];
  167. //分享图片
  168. [UIView animateWithDuration:0.2f animations:^{
  169. self.shareView.frame=CGRectMake(0, SCREEN_HEIGHT-200-SafeBottomHeight, SCREEN_WIDTH, 200+SafeBottomHeight);
  170. }];
  171. };
  172. imgView.model=model;
  173. }
  174. break;
  175. default:
  176. break;
  177. }
  178. }
  179. -(void)setInviteCode:(NSString *)inviteCode{
  180. _inviteCode=inviteCode;
  181. self.inviteNumber.text=[NSString stringWithFormat:@"我的邀请码:%@",inviteCode];
  182. [self.inviteNumber sizeToFit];
  183. self.inviteNumber.centerX=self.view.centerX;
  184. }
  185. -(UIView *)shareView{
  186. if (!_shareView) {
  187. _shareView=[[[NSBundle mainBundle] loadNibNamed:@"shareView" owner:self options:nil] lastObject];
  188. _shareView.frame=CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH,SCREEN_HEIGHT);
  189. [_shareView.cancelButton addTarget:self action:@selector(doTapChange) forControlEvents:UIControlEventTouchUpInside];
  190. WeakSelf(weakSelf)
  191. _shareView.shareButtonTwoBlock=^(void){
  192. __strong typeof(self) strongSelf=weakSelf;
  193. [strongSelf doTapChange];
  194. };
  195. _shareView.shareButtonOneBlock=^(void){
  196. __strong typeof(self) strongSelf=weakSelf;
  197. [strongSelf doTapChange];
  198. };
  199. }
  200. return _shareView;
  201. }
  202. -(UIView *)backShareView{
  203. if (!_backShareView) {
  204. _backShareView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  205. _backShareView.backgroundColor=[[UIColor blackColor] colorWithAlphaComponent:0.3f];
  206. _backShareView.hidden=YES;
  207. UITapGestureRecognizer *r5 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doTapChange)];
  208. r5.numberOfTapsRequired = 1;
  209. [_backShareView addGestureRecognizer:r5];
  210. }
  211. return _backShareView;
  212. }
  213. @end