口袋优选

KBInviteFansViewController.m 11KB

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