123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- //
- // XYLiveRoomShareView.m
- // Starbuds
- //
- // Created by pajia on 2020/1/14.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYLiveRoomShareView.h"
- #import "XYSocialShareHandler.h"
- #import <SDWebImagePrefetcher.h>
- #import "SDImageCache.h"
- #import "UIImage+Save.h"
- #import "UIView+Snapshot.h"
- @interface XYLiveRoomShareViewItemView : BaseView
- @property (nonatomic, strong) UIImageView *imgView;
- @property (nonatomic, strong) UILabel *disLab;;
- - (void)setup;
- - (void)reload:(NSDictionary *)dataDict andSelect:(BOOL )select;
- @end
- @implementation XYLiveRoomShareViewItemView
- - (void)setup{
- self.backgroundColor = [UIColor clearColor];
-
- _imgView = [[UIImageView alloc] init];
- _imgView.contentMode = UIViewContentModeScaleAspectFill;
- [self addSubview:_imgView];
- [_imgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.mas_top).offset(0);
- make.left.equalTo(self.mas_left).offset(0);
- make.width.offset(53);
- make.height.offset(53);
- }];
- [_imgView layoutIfNeeded];
-
- _disLab = [[UILabel alloc] init];
- _disLab.font = [UIFont fontWithName:kPFSCFont size:12];
- _disLab.textColor = [UIColor colorWithHexString:@"#FAFBFC" alpha:0.5];
- _disLab.text = @"-";
- [_disLab sizeToFit];
- [self addSubview:_disLab];
- [_disLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(_imgView.mas_bottom).offset(8);
- make.centerX.equalTo(_imgView.mas_centerX).offset(0);
- }];
- [_disLab layoutIfNeeded];
-
- }
- - (void)reload:(NSDictionary *)dataDict andSelect:(BOOL )select{
- _imgView.image = [UIImage imageNamed:dataDict[@"image"]];
- _disLab.text = dataDict[@"dis"];
- }
- @end
- @interface XYLiveRoomShareView(){
-
- }
- @property (nonatomic, readwrite, strong) UIView *tapView;
- @property (nonatomic, readwrite, strong) UIView *shadowView;
- @property (nonatomic, readwrite, strong) NSMutableArray *dataArrs;
- @property (nonatomic, readwrite, strong) NSMutableArray *viewArrs;
- @property (nonatomic, readwrite, strong) UILabel *titleLab;
- @property (nonatomic, readwrite, strong) UIImageView *shareImgView;
- @property (nonatomic, readwrite, assign) int type;
- @end
- @implementation XYLiveRoomShareView
- - (void)setup:(int )type{
- self.type = type;
- self.tapView.hidden = YES;
- self.hidden = YES;
-
- self.backgroundColor = [UIColor clearColor];
-
- _dataArrs = [[NSMutableArray alloc] init];
- ///是否安装微信
- if ([XYSocialRegisterHandler isWXAppInstalled] && StringIsNotEmpty([XYAppConfigOauthsModel getOauthsModelWithType:XY_Login_type_WX_Login])) {
- if (type == 1) {
- [_dataArrs addObject:@{@"image":@"xy-lr-icon-share1",@"dis":kLocalizedString(@"微信好友")}];
- [_dataArrs addObject:@{@"image":@"xy-lr-icon-share2",@"dis":kLocalizedString(@"朋友圈")}];
- }else if (type == 2){
- [_dataArrs addObject:@{@"image":@"icon_invitefriendposter_wweixin",@"dis":kLocalizedString(@"微信好友")}];
- [_dataArrs addObject:@{@"image":@"icon_invitefriendposter_frirendcircle",@"dis":kLocalizedString(@"朋友圈")}];
- }
-
- }
- ///是否安装QQ
- if ([XYSocialRegisterHandler isQQAppInstalled] && StringIsNotEmpty([XYAppConfigOauthsModel getOauthsModelWithType:XY_Login_type_QQ_Login])) {
- if (type == 1) {
- [_dataArrs addObject:@{@"image":@"xy-lr-icon-share4",@"dis":kLocalizedString(@"QQ好友")}];
- }else if (type == 2){
- [_dataArrs addObject:@{@"image":@"icon_invitefriendposter_qq",@"dis":kLocalizedString(@"QQ好友")}];
- }
-
- }
- // 是否安装微博
- if ([XYSocialRegisterHandler isSinaAppInstalled] && StringIsNotEmpty([XYAppConfigOauthsModel getOauthsModelWithType:XY_Login_type_Sina_Login])) {
- if (type == 1) {
- [_dataArrs addObject:@{@"image":@"xy-lr-icon-share3",@"dis":kLocalizedString(@"微博")}];
- }else if (type == 2){
- [_dataArrs addObject:@{@"image":@"icon_invitefriendposter_weibo",@"dis":kLocalizedString(@"微博")}];
- }
- }
-
- if (type == 1) {
- [_dataArrs addObject:@{@"image":@"xy-lr-icon-share5",@"dis":kLocalizedString(@"复制链接")}];
- }else if (type == 2){
- [_dataArrs addObject:@{@"image":@"icon_invitefriendposter_saveimage",@"dis":kLocalizedString(@"保存图片")}];
- }
-
- _viewArrs = [[NSMutableArray alloc] init];
-
- _tapView = [[UIView alloc] init];
- _tapView.backgroundColor = [UIColor clearColor];
- [self addSubview:_tapView];
- _tapView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapViewAction)];
- _tapView.userInteractionEnabled = YES;
- [_tapView addGestureRecognizer:tap];
-
- _shadowView = [[UIView alloc] init];
- _shadowView.backgroundColor = [UIColor colorWithHexString:@"#15061A" alpha:0.8];
- [self addSubview:_shadowView];
- _shadowView.frame = CGRectMake(0, kScreenHeight, kScreenWidth, 155+kiPhoneXBottomEdge);
- UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, _shadowView.f_width, _shadowView.f_heigh) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(16, 16)];
- CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
- maskLayer.frame = CGRectMake(0, 0, _shadowView.f_width, _shadowView.f_heigh);
- maskLayer.path = maskPath.CGPath;
- _shadowView.layer.mask = maskLayer;
-
- UILabel *titleLab = [[UILabel alloc] init];
- self.titleLab = titleLab;
- titleLab.font = [UIFont fontWithName:kPFSCMediumFont size:16];
- titleLab.textColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:2];
- titleLab.text = kLocalizedString(@"分享给小伙伴,帮主播加油");
- [titleLab sizeToFit];
- [_shadowView addSubview:titleLab];
- [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(_shadowView.mas_top).offset(20);
- make.centerX.equalTo(_shadowView.mas_centerX).offset(0);
- }];
- [titleLab layoutIfNeeded];
- UITapGestureRecognizer *titleLabtap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(titleLabAction)];
- //titleLabtap.numberOfTouchesRequired = 2;
- titleLabtap.numberOfTapsRequired = 5;
- titleLab.userInteractionEnabled = YES;
- [titleLab addGestureRecognizer:titleLabtap];
-
- _shareImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
- [_shareImgView sd_setImageWithURL:[NSURL URLWithString:self.liveRoomVCInfo.sharePic] placeholderImage:placeholderImage()];
- _shareImgView.hidden = YES;
- [_shadowView addSubview:_shareImgView];
-
- float itemWidth = 53;
- float itemHeight = 76;
- float itemEdge = 20;
- UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake((kScreenWidth-(itemWidth*self.dataArrs.count+itemEdge*(self.dataArrs.count-1)))/2.0, 62, itemWidth*self.dataArrs.count+itemEdge*(self.dataArrs.count-1), _shadowView.f_heigh-62)];
- contentView.backgroundColor = [UIColor clearColor];
- [_shadowView addSubview:contentView];
- for (int i = 0; i < self.dataArrs.count ; i++) {
- XYLiveRoomShareViewItemView *itemView = [[XYLiveRoomShareViewItemView alloc] init];
- [itemView setup];
- if (type == 2) {
- itemView.disLab.font = [UIFont fontWithName:kPFSCFont size:12];
- itemView.disLab.textColor = [UIColor colorWithHexString:@"#909399" alpha:1];
- }
- itemView.frame = CGRectMake(i*itemEdge+i*itemWidth, 0, itemWidth, itemHeight);
- itemView.tag = i;
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(itemViewAction:)];
- itemView.userInteractionEnabled = YES;
- [itemView addGestureRecognizer:tap];
- [contentView addSubview:itemView];
- [self.viewArrs addObject:itemView];
- [itemView reload:_dataArrs[i] andSelect:NO];
- }
-
- if (type == 2) {
- UILabel *lineLab = [[UILabel alloc] init];
- lineLab.backgroundColor = [UIColor colorWithHexString:@"#DDDFE7" alpha:0.5];
- [lineLab sizeToFit];
- [_shadowView insertSubview:lineLab atIndex:0];
- [lineLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(_shadowView.mas_left).offset(30);
- make.right.equalTo(_shadowView.mas_right).offset(-30);
- make.centerY.equalTo(titleLab.mas_centerY).offset(0);
- make.height.offset(1);
- }];
- [lineLab layoutIfNeeded];
-
- self.shadowView.backgroundColor = [UIColor whiteColor];
- self.titleLab.text = kLocalizedString(@" 分享到 ");
- self.titleLab.font = [UIFont fontWithName:kPFSCFont size:11];
- self.titleLab.textColor = [UIColor colorWithHexString:@"#606266" alpha:1];
- self.titleLab.backgroundColor = [UIColor colorWithHexString:@"#ffffff" alpha:1];
- self.tapView.hidden = YES;
- self.hidden = NO;
- self.shadowView.frame = CGRectMake(0, kScreenHeight-self.shadowView.f_heigh, kScreenWidth, self.shadowView.f_heigh);
-
- [titleLab mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(_shadowView.mas_top).offset(40);
- make.centerX.equalTo(_shadowView.mas_centerX).offset(0);
- }];
- }
-
- }
- - (void)titleLabAction{
- [XYLiveManger shareInstance].HDWindowLoggerShow = ![XYLiveManger shareInstance].HDWindowLoggerShow;
- if ([XYLiveManger shareInstance].HDWindowLoggerShow) {
- [SVProgressHUD showInfoWithStatus:@"show"];
- [[NSUserDefaults standardUserDefaults] setObject:@"HDWindowLoggerShow" forKey:@"HDWindowLoggerShow"];
- }else{
- [SVProgressHUD showInfoWithStatus:@"hide"];
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"HDWindowLoggerShow"];
- }
- }
- - (void)setLiveRoomVCInfo:(XYLiveRoomVCInfo *)liveRoomVCInfo{
- _liveRoomVCInfo = liveRoomVCInfo;
-
- if (!liveRoomVCInfo.shareUrl.length) {
- return;
- }
-
- // [_shareImgView sd_setImageWithURL:[NSURL URLWithString:self.liveRoomVCInfo.sharePic] placeholderImage:placeholderImage()];
-
- [[SDWebImagePrefetcher sharedImagePrefetcher] prefetchURLs:@[[NSURL URLWithString:self.liveRoomVCInfo.sharePic]] progress:^(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls) {
- } completed:^(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls) {
- }];
-
- // SDWebImageManager *manager = [SDWebImageManager sharedManager] ;
- // [manager downloadImageWithURL:[NSURL URLWithString:self.liveRoomVCInfo.sharePic] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
- // // progression tracking code
- // } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
- // if (image) {
- // self.shareImgView.image = image;
- // }
- // }];
- }
- - (void)show{
- self.tapView.hidden = NO;
- self.hidden = NO;
- kWEAKSELF
- [UIView animateWithDuration:0.3 animations:^{
- weakSelf.shadowView.frame = CGRectMake(0, kScreenHeight-weakSelf.shadowView.f_heigh, kScreenWidth, weakSelf.shadowView.f_heigh);
- } completion:^(BOOL finished) {
-
- }];
- }
- - (void)tapViewAction{
- kWEAKSELF
- [UIView animateWithDuration:0.3 animations:^{
- weakSelf.shadowView.frame = CGRectMake(0, kScreenHeight, kScreenWidth, weakSelf.shadowView.f_heigh);
- } completion:^(BOOL finished) {
- weakSelf.tapView.hidden = YES;
- weakSelf.hidden = YES;
- }];
- }
- - (void)itemViewAction:(UITapGestureRecognizer *)tapges{
- UIImage *image1;
- UIImage *image2;
- if (self.type == 1) {
- NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:[NSURL URLWithString:self.liveRoomVCInfo.sharePic]];
- image1 = [[SDImageCache sharedImageCache] imageFromCacheForKey:key];
-
- }else if (self.type == 2){
- image2 = [self.liveRoomVCInfo.shareImageView snapshotImage];
- }
- //UIImage *image = self.shareImgView.image;
-
- UIView *view = [tapges view];
- NSInteger tag = view.tag;
- NSString *name = self.dataArrs[tag][@"dis"];
- if ([name isEqualToString:kLocalizedString(@"微信好友")]) {//微信好友
- if (self.type == 1) {
- [[XYSocialShareHandler sharedInstance] share_WXURLWithTitle:self.liveRoomVCInfo.shareTitle description:self.liveRoomVCInfo.shareSubTitle thumbImage:image1 url:self.liveRoomVCInfo.shareUrl];
-
- }else if (self.type == 2){
- [[XYSocialShareHandler sharedInstance] share_WXImageWithImage:image2 thumbImage:image2];
- }
-
- }else if ([name isEqualToString:kLocalizedString(@"朋友圈")]){//朋友圈
- if (self.type == 1) {
- [[XYSocialShareHandler sharedInstance] share_PYQURLWithTitle:self.liveRoomVCInfo.shareTitle description:self.liveRoomVCInfo.shareSubTitle thumbImage:image1 url:self.liveRoomVCInfo.shareUrl];
-
- }else if (self.type == 2){
- [[XYSocialShareHandler sharedInstance] share_PYQImageWithImage:image2 thumbImage:image2];
- }
-
-
- }else if ([name isEqualToString:kLocalizedString(@"微博")]){//微博
- if (self.type == 1) {
- [[XYSocialShareHandler sharedInstance] share_sinaUrlWithUrl:self.liveRoomVCInfo.shareUrl title:self.liveRoomVCInfo.shareTitle description:self.liveRoomVCInfo.shareSubTitle thumbImage:image1];
-
- }else if (self.type == 2){
- [[XYSocialShareHandler sharedInstance] share_sinaImageWithImages:@[image2]];
- }
-
-
- }else if ([name isEqualToString:kLocalizedString(@"QQ好友")]){//qq好友
- if (self.type == 1) {
- [[XYSocialShareHandler sharedInstance] share_QQUrlWithUrl:self.liveRoomVCInfo.shareUrl title:self.liveRoomVCInfo.shareTitle description:self.liveRoomVCInfo.shareSubTitle previewImageURL:self.liveRoomVCInfo.sharePic shareType:1];
-
- }else if (self.type == 2){
- [[XYSocialShareHandler sharedInstance] share_QQImageWithImage:image2 title:@"" description:@"" shareType:1];
-
- }
-
- }else if ([name isEqualToString:kLocalizedString(@"复制链接")] || [name isEqualToString:kLocalizedString(@"保存图片")] ){//复制链接
- if (self.type == 1) {
- if (!self.liveRoomVCInfo.shareUrl.length) { return; }
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- pasteboard.string = self.liveRoomVCInfo.shareUrl;
- [SVProgressHUD showSuccessWithStatus:kLocalizedString(@"已复制至剪切板")];
-
- }else if (self.type == 2){
- [image2 saveImageToPhotoAlbumWithImage:image2 completion:^(BOOL success, NSError * _Nullable error) {
- if (success) {
- [SVProgressHUD showSuccessWithStatus:kLocalizedString(@"已保存图片")];
- }
- }];
-
- }
- }
- }
- - (void)clear{
-
- }
- @end
|