123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- //
- // KBInviteFansViewController.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/5/19.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "KBInviteFansViewController.h"
- #import "KBInviteBannerView.h"
- #import "shareView.h"
- #import "KBShareGetFriendsView.h"
- #import "KBPrivilegeReferralViewController.h"
- @interface KBInviteFansViewController ()<YHInviteBannerDelegate>
- @property(nonatomic,strong)UIView *backShareView;
- @property(nonatomic,strong)shareView *shareView;
- @property(nonatomic,strong)UILabel *inviteNumber;
- @property(nonatomic,strong)KBInviteBannerView *bannerView;
- @property(nonatomic,copy)NSString *inviteCode;
- @property(nonatomic,copy)NSString *shareUrl;
- @property(nonatomic,copy)NSString *headimg;
- @property(nonatomic,copy)NSString *nickName;
- @property(nonatomic) NSInteger selectIndex;//当前选中海报
- @property(nonatomic,strong)NSNumber *flag;
- @end
- @implementation KBInviteFansViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self configNavigationBar];
- [self configUI];
-
- }
- -(void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
- self.flag=@(-1);
- [self request];
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- [SVProgressHUD dismiss];
- }
- - (void)configNavigationBar {
- [self.navigationBar setNavTitle:@"邀请好友"];
- self.navigationBar.backgroundColor = [UIColor changeColor];
- self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
- UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
- [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
- [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
- [self.navigationBar setCustomLeftButtons:@[leftBtn]];
- }
- - (void)backAction {
- [self.navigationController popViewControllerAnimated:YES];
- }
- -(void)request{
-
- [SVProgressHUD show];
- NSString *url=[NSString stringWithFormat:@"%@/api/v2/users/inviteFriends",BaseURL];
- [KBHttp post:url params:nil success:^(id json) {
- if (json) {
- NSArray *imgArr=json[@"imgs"];
- NSString *code=json[@"invite_code"];
- NSString *shareUrl=json[@"share_url"];
- self.inviteCode=[NSString stringWithFormat:@"%@",code];
- self.shareUrl=shareUrl;
- self.bannerView.dataArr=[NSArray arrayWithArray:imgArr];
- self.nickName = json[@"nickname"];
- self.headimg = json[@"headimg"];
- }
-
- [SVProgressHUD dismiss];
- } failure:^(NSError *error) {
- [SVProgressHUD dismiss];
- }];
- NSString *url2=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/userIdentity",BaseURL];
- [KBHttp post:url2 params:nil success:^(id json) {
- if (json) {
- self.flag=json[@"data"][@"flag"];
- if ([self.flag integerValue]<2) {
- self.inviteNumber.hidden=YES;
- }
- }
- } failure:^(NSError *error) {
-
- }];
-
- }
- - (void)configUI {
-
- self.view.backgroundColor = [UIColor whiteColor];
- UILabel *desLabel = [[UILabel alloc] initWithFrame:CGRectMake(28, NavBarHeight+Fitsize(31), SCREEN_WIDTH-56, 40)];
- desLabel.numberOfLines = 2;
- desLabel.text = @"分享专属海报,新用户注册后直接成为你的粉丝\n1.微信扫码下载->2.微信登录->3.成为你的粉丝";
- desLabel.font = [UIFont systemFontOfSize:14];
- desLabel.textColor = [UIColor YHColorWithHex:0x666666];
- desLabel.textAlignment = NSTextAlignmentCenter;
- [self.view addSubview:desLabel];
-
- KBInviteBannerView *bannerView = [[KBInviteBannerView alloc] initWithFrame:CGRectMake(0, desLabel.bottom+Fitsize(32), SCREEN_WIDTH, Fitsize(360))];
- bannerView.delegate=self;
- bannerView.layer.masksToBounds=YES;
- [self.view addSubview:bannerView];
- self.bannerView=bannerView;
-
-
- UILabel *inviteNumber = [[UILabel alloc] initWithFrame:CGRectMake(0, bannerView.bottom+Fitsize(34), 200, 20)];
- inviteNumber.textColor = [UIColor YHColorWithHex:0x333333];
- inviteNumber.font = [UIFont boldSystemFontOfSize:14];
- inviteNumber.text = @"我的邀请码:--------";
- [inviteNumber sizeToFit];
- [self.view addSubview:inviteNumber];
- self.inviteNumber=inviteNumber;
- inviteNumber.centerX = self.view.centerX;
-
- NSInteger offInt=0;
- if (iPhoneX) {
- offInt=50;
- }
-
- UIButton *shareLink = [[UIButton alloc] initWithFrame:CGRectMake(10, SCREEN_HEIGHT-Fitsize(55)-offInt, (self.view.width-30)/2, Fitsize(40))];
- [shareLink setTitle:@"复制邀请码" forState:UIControlStateNormal];
- shareLink.backgroundColor = [UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0xFEC800] toColor:[UIColor YHColorWithHex:0xFD9D03] withWidth:shareLink.width];
- shareLink.layer.cornerRadius = 4;
- shareLink.tag=10001;
- shareLink.titleLabel.font = [UIFont systemFontOfSize:Fitsize(16)];
- [shareLink addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
- [shareLink setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [self.view addSubview:shareLink];
-
- UIButton *shareImg = [[UIButton alloc] initWithFrame:CGRectMake(shareLink.right+5, shareLink.top, (self.view.width-30)/2, Fitsize(40))];
- shareImg.tag=10002;
- shareImg.backgroundColor = [UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0xFE6735] toColor:[UIColor YHColorWithHex:0xFF2D23] withWidth:shareLink.width];
- [shareImg setTitle:@"分享专属海报" forState:UIControlStateNormal];
- [shareImg addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
- [shareImg setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- shareImg.layer.cornerRadius = 4;
- shareImg.titleLabel.font = [UIFont systemFontOfSize:Fitsize(16)];
- [self.view addSubview:shareImg];
- [[UIApplication sharedApplication].keyWindow addSubview:self.backShareView];
- [[UIApplication sharedApplication].keyWindow addSubview:self.shareView];
- }
- -(void)doTapChange{
- self.backShareView.hidden=YES;
- [UIView animateWithDuration:0.2f animations:^{
- self.shareView.frame=CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 200+SafeBottomHeight);
- } completion:^(BOOL finished) {
- }];
- }
- -(void)didCurrentCellAtIndex:(NSInteger)index{
- self.selectIndex=index;
- }
- -(void)shareAction:(UIButton *)sender{
- if ([self.flag integerValue]==0 ||[self.flag integerValue]==1) {
- UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"邀请好友" message:[NSString stringWithFormat:@"\n您还不是超级会员,升级到超级会员才能邀请好友"] preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"去升级" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
- KBPrivilegeReferralViewController *vc=[[KBPrivilegeReferralViewController alloc]init];
- [self.navigationController pushViewController:vc animated:YES];
- }];
- UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
- }];
- [alert addAction:cancelAction];
- [alert addAction:defaultAction];
- [self presentViewController:alert animated:YES completion:nil];
- return;
- }else if([self.flag integerValue]==-1){
- [MBProgressHUD showMessage:@"正在确认您的等级"];
- }
-
- switch (sender.tag) {
- case 10001:
- {
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- pasteboard.string =[NSString stringWithFormat:@"%@",self.inviteCode];
- [MBProgressHUD showTip:@"复制成功"];
- }
- break;
- case 10002:
- {
- self.backShareView.hidden=NO;
- KBShareGetFriendsView *imgView=[[KBShareGetFriendsView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- KBShareGetFriendsModel *model=[[KBShareGetFriendsModel alloc]init];
- model.getFriendCode=self.inviteCode;
- model.QRcodeUrl=self.shareUrl;
- model.imgUrl=self.bannerView.dataArr[self.selectIndex];
- model.inviteCode = self.inviteCode;
- model.headimg = self.headimg;
- model.nickname = self.nickName;
- self.shareView.imgUrl = model.imgUrl;
- __weak KBShareGetFriendsView *wkimgView=imgView;
- imgView.imgSuccBlock = ^{
- UIImage *img=[wkimgView changeToImage];
- [self.shareView shareImage:img];
- //分享图片
- [UIView animateWithDuration:0.2f animations:^{
- self.shareView.frame=CGRectMake(0, SCREEN_HEIGHT-200-SafeBottomHeight, SCREEN_WIDTH, 200+SafeBottomHeight);
- }];
- };
- imgView.model=model;
- }
- break;
- default:
- break;
- }
- }
- -(void)setInviteCode:(NSString *)inviteCode{
- _inviteCode=inviteCode;
- self.inviteNumber.text=[NSString stringWithFormat:@"我的邀请码:%@",inviteCode];
- [self.inviteNumber sizeToFit];
- self.inviteNumber.centerX=self.view.centerX;
- }
- -(UIView *)shareView{
- if (!_shareView) {
- _shareView=[[[NSBundle mainBundle] loadNibNamed:@"shareView" owner:self options:nil] lastObject];
- _shareView.frame=CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH,SCREEN_HEIGHT);
- [_shareView.cancelButton addTarget:self action:@selector(doTapChange) forControlEvents:UIControlEventTouchUpInside];
- WeakSelf(weakSelf)
- _shareView.shareButtonTwoBlock=^(void){
- __strong typeof(self) strongSelf=weakSelf;
- [strongSelf doTapChange];
- };
- _shareView.shareButtonOneBlock=^(void){
- __strong typeof(self) strongSelf=weakSelf;
- [strongSelf doTapChange];
- };
- }
- return _shareView;
- }
- -(UIView *)backShareView{
- if (!_backShareView) {
- _backShareView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- _backShareView.backgroundColor=[[UIColor blackColor] colorWithAlphaComponent:0.3f];
- _backShareView.hidden=YES;
- UITapGestureRecognizer *r5 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doTapChange)];
- r5.numberOfTapsRequired = 1;
- [_backShareView addGestureRecognizer:r5];
- }
- return _backShareView;
- }
- @end
|