123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- //
- // XYInviteFriendsController.m
- // Starbuds
- //
- // Created by gy on 2020/5/20.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYInviteFriendsController.h"
- #import "XYLiveRoomShareView.h"
- #import "NewPagedFlowView.h"
- #import <SDWebImagePrefetcher.h>
- #import "SDImageCache.h"
- #import "CodeHandlerObject.h"
- #import "UIView+AZGradient.h"
- #import "UIView+Snapshot.h"
- #import "XYInviteFriendsHistoryController.h"
- @interface XYInviteFriendsController ()<NewPagedFlowViewDelegate, NewPagedFlowViewDataSource>
- @property (nonatomic, strong) XYLiveRoomShareView *liveRoomShareView;
- @property (nonatomic, strong) NSMutableArray *imageArray;
- @property (nonatomic, strong) NewPagedFlowView *pageFlowView;
- @end
- @implementation XYInviteFriendsController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- self.view.backgroundColor = [UIColor whiteColor];
- self.title = kLocalizedString(@"邀请好友");
-
- UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [rightBtn setTitle:@"记录" forState:UIControlStateNormal];
- [rightBtn setTitleColor:[UIColor colorWithHexString:@"#303133" alpha:1] forState:UIControlStateNormal];
- rightBtn.titleLabel.font = [UIFont fontWithName:kPFSCFont size:16];
- [rightBtn addTarget:self action:@selector(rightBtnAction) forControlEvents:UIControlEventTouchUpInside];
- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
-
- [SVProgressHUD showWithStatus:nil];
-
- kWEAKSELF
- [[XYUserAPIManager new] getPosterImages:nil successHandler:^(ZYLResponseModel *responseModel) {
- [SVProgressHUD dismiss];
- [weakSelf setup:responseModel.data];
-
- } failureHandler:^(ZYLNetworkError *error) {
- [SVProgressHUD dismiss];
- [SVProgressHUD showInfoWithStatus:error.domain];
- }];
- }
- - (void)rightBtnAction{
- XYInviteFriendsHistoryController *vc = [[XYInviteFriendsHistoryController alloc] init];
- [self.navigationController pushViewController:vc animated:YES];
-
- }
- - (void)setup:(NSDictionary *)data{
-
- NSArray *list = data[@"list"];
- for (NSDictionary *dict in list) {
- XYLiveRoomVCInfo *info = [[XYLiveRoomVCInfo alloc] init];
- info.sharePic = dict[@"imageUrl"];
- info.shareSubTitle = dict[@"inviteCode"];
- info.shareUrl = dict[@"posterLink"];
- [self.imageArray addObject:info];
- }
-
- [self.view addSubview:self.liveRoomShareView];
-
- for (XYLiveRoomVCInfo *info in self.imageArray) {
- [[SDWebImagePrefetcher sharedImagePrefetcher] prefetchURLs:@[[NSURL URLWithString:info.sharePic]] progress:^(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls) {
- } completed:^(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls) {
- }];
- }
-
- NewPagedFlowView *pageFlowView = [[NewPagedFlowView alloc] initWithFrame:CGRectMake(0, 72+kiPhoneXTopEdge, kScreenWidth, kScreenHeight-72-kiPhoneXTopEdge-152-kiPhoneXBottomEdge)];
- self.pageFlowView = pageFlowView;
- pageFlowView.delegate = self;
- pageFlowView.dataSource = self;
- pageFlowView.minimumPageAlpha = 0.1;
- pageFlowView.leftRightMargin = 35;
- pageFlowView.topBottomMargin = 55;
- pageFlowView.isCarousel = YES;
- pageFlowView.orientation = NewPagedFlowViewOrientationHorizontal;
- pageFlowView.isOpenAutoScroll = NO;
-
- //初始化pageControl
- UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, pageFlowView.f_y + pageFlowView.f_heigh + 18, kScreenWidth, 8)];
- pageControl.pageIndicatorTintColor = [UIColor colorWithHexString:@"#EFEFEF"alpha:1];
- pageControl.currentPageIndicatorTintColor = [UIColor colorWithHexString:@"#FF4D5C"alpha:1];
- pageFlowView.pageControl = pageControl;
- [self.view addSubview:pageControl];
-
- [pageFlowView reloadData];
- if (self.imageArray.count > 1) {
- [pageFlowView scrollToPage:self.imageArray.count/2];
- }
- [self shareCodeImg:(int )self.imageArray.count/2];
-
-
- [self.view addSubview:pageFlowView];
-
- }
- - (XYLiveRoomShareView *)liveRoomShareView{
- if (_liveRoomShareView == nil) {
- _liveRoomShareView = [[XYLiveRoomShareView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
- [self.view addSubview:_liveRoomShareView];
- [_liveRoomShareView setup:2];
- }
- return _liveRoomShareView;
- }
- #pragma mark NewPagedFlowView Delegate
- - (CGSize)sizeForPageInFlowView:(NewPagedFlowView *)flowView {
- return CGSizeMake(self.pageFlowView.f_width-62*2, self.pageFlowView.f_heigh);
-
- }
- - (void)didSelectCell:(UIView *)subView withSubViewIndex:(NSInteger)subIndex {
- NSLog(@"点击了第%ld张图",(long)subIndex + 1);
-
- }
- - (void)didScrollToPage:(NSInteger)pageNumber inFlowView:(NewPagedFlowView *)flowView {
- NSLog(@"ViewController 滚动到了第%ld页",pageNumber);
- [self shareCodeImg:(int )pageNumber];
- }
- #pragma mark NewPagedFlowView Datasource
- - (NSInteger)numberOfPagesInFlowView:(NewPagedFlowView *)flowView {
- return self.imageArray.count;
-
- }
- - (PGIndexBannerSubiew *)flowView:(NewPagedFlowView *)flowView cellForPageAtIndex:(NSInteger)index{
- PGIndexBannerSubiew *bannerView = [flowView dequeueReusableCell];
- if (!bannerView) {
- bannerView = [[PGIndexBannerSubiew alloc] init];
- bannerView.tag = index;
- bannerView.layer.cornerRadius = 4;
- bannerView.layer.masksToBounds = YES;
- }
- XYLiveRoomVCInfo *info = self.imageArray[index];
- [bannerView.mainImageView sd_setImageWithURL:[NSURL URLWithString:info.sharePic] placeholderImage:placeholderImage()];
- NSString *path = info.shareUrl;
- UIImage *image = [CodeHandlerObject createCodeWithUrl:path withSize:104];
- bannerView.codeImgView.image = image;
- bannerView.userIdLab.text = [NSString stringWithFormat:@"%@%@",kLocalizedString(@"邀请码:"),info.shareSubTitle];
- //bannerView.mainImageView.image = self.imageArray[index];
-
- return bannerView;
- }
- - (NSMutableArray *)imageArray {
- if (_imageArray == nil) {
- _imageArray = [NSMutableArray array];
- }
- return _imageArray;
- }
- - (void)shareCodeImg:(int )index{
- XYLiveRoomVCInfo *info = self.imageArray[index];
-
- if (!info.sharePic.length) { return; }
-
- self.liveRoomShareView.liveRoomVCInfo = info;
-
- NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:[NSURL URLWithString:info.sharePic]];
- UIImage *image = [[SDImageCache sharedImageCache] imageFromCacheForKey:key];
- UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
- bgImageView.contentMode = UIViewContentModeScaleAspectFill;
-
- UIImageView *codeImageView = [[UIImageView alloc] initWithFrame:CGRectMake((kScreenWidth-104)/2.0, kScreenHeight-44-104, 104, 104)];
- NSString *path = info.shareUrl;
- codeImageView.image = [CodeHandlerObject createCodeWithUrl:path withSize:codeImageView.f_heigh];
- [bgImageView addSubview:codeImageView];
- kViewRadius(codeImageView, 4);
-
- UILabel *userIdLab = [[UILabel alloc] initWithFrame: CGRectMake((kScreenWidth-124)/2.0, codeImageView.f_y+codeImageView.f_heigh+8, 124, 20)];
- userIdLab.textColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1];
- userIdLab.font = [UIFont fontWithName:kPFSCMediumFont size:12];
- userIdLab.textAlignment = NSTextAlignmentCenter;
- [userIdLab az_setGradientBackgroundWithColors:@[ColorFromHexString(@"#5D26FF"), ColorFromHexString(@"#9059FF")] locations:nil startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
- kViewRadius(userIdLab, 10);
- userIdLab.text = [NSString stringWithFormat:@"%@%@",kLocalizedString(@"邀请码:"),info.shareSubTitle];
- [bgImageView addSubview:userIdLab];
-
- if (image) {
- bgImageView.image = image;
- self.liveRoomShareView.liveRoomVCInfo.shareImageView = bgImageView;
-
- }else{
- kWEAKSELF
- [[SDWebImagePrefetcher sharedImagePrefetcher] prefetchURLs:@[[NSURL URLWithString:info.sharePic]] progress:^(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls) {
- } completed:^(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls) {
- NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:[NSURL URLWithString:info.sharePic]];
- bgImageView.image = [[SDImageCache sharedImageCache] imageFromCacheForKey:key];
- weakSelf.liveRoomShareView.liveRoomVCInfo.shareImageView = bgImageView;
-
- }];
- }
-
- }
- /*
- #pragma mark - Navigation
-
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|