// // YOUPAILZLiveCloseAudienceWindow.m // TIANYAN // // Created by CY on 2021/5/26. // Copyright © 2021 leo. All rights reserved. // #import "YOUPAILZLiveCloseAudienceWindow.h" #import "YYAnimatedImageView.h" #import "YYImage.h" @interface YOUPAILZLiveCloseAudienceWindow () @property (nonatomic, strong) YOUPAILZLiveCloseModel *youpaipmodel; @property (nonatomic, strong) UILabel *youpaipnicknameL; @property (nonatomic, weak) UIButton *youpaipfollowBtn; // 关注按钮 @property (nonatomic, weak) UIView *youpaiprecommendBgV; // 推荐背景View @property(nonatomic,strong)UIButton *youpaiptransformBtn;//换一批 @property(nonatomic,strong)UILabel *youpaiprecommendL;// @property(nonatomic,strong)UIView *youpaiplineV;//线 @end @implementation YOUPAILZLiveCloseAudienceWindow - (instancetype)initWithModel:(YOUPAILZLiveCloseModel *)model{ if (self = [super init]) { _youpaipmodel = model; } return self; } - (void)viewDidLoad { [super viewDidLoad]; self.baseView.hidden = YES; [self youpaifinitUI]; } - (void)youpaifinitUI{ UIView *bgV = [[UIView alloc] init]; bgV.backgroundColor = HexColorFromRGB(0x2A2935); bgV.layer.cornerRadius = 10.0f; bgV.clipsToBounds = YES; [self.view addSubview:bgV]; [bgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(32.0f); make.right.offset(-32.0f); make.centerY.equalTo(self.view.mas_centerY); }]; UIButton *youpaipcloseBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [youpaipcloseBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_window_close1"] forState:UIControlStateNormal]; [youpaipcloseBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_window_close1"] forState:UIControlStateHighlighted]; [youpaipcloseBtn addTarget:self action:@selector(youpaifcloseBtnClick) forControlEvents:UIControlEventTouchUpInside]; [bgV addSubview:youpaipcloseBtn]; [youpaipcloseBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.offset(7.0f); make.right.offset(-7.0f); make.size.mas_offset(CGSizeMake(28, 28)); }]; UILabel *titleL = [[UILabel alloc] init]; titleL.font = LCBoldFont(19.0f); titleL.textColor = HexColorFromRGB(0xffffff); titleL.text = @"直播结束"; [bgV addSubview:titleL]; [titleL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.offset(25.0f); make.centerX.equalTo(bgV.mas_centerX); }]; UILabel *subTitleL = [[UILabel alloc] init]; subTitleL.font = LCFont14; subTitleL.textColor = HexColorFromRGB(0x9F9DA5); subTitleL.text = @"关注TA订阅下次直播通知哦~"; [bgV addSubview:subTitleL]; [subTitleL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(titleL.mas_bottom).offset(7.0f); make.centerX.equalTo(bgV.mas_centerX); }]; UIImageView *youpaipavatarImgV = [[UIImageView alloc] init]; youpaipavatarImgV.contentMode = UIViewContentModeScaleAspectFill; youpaipavatarImgV.layer.cornerRadius = 32.0f; youpaipavatarImgV.clipsToBounds = YES; [youpaipavatarImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.youpaipmodel.youpaipavatar]]; [bgV addSubview:youpaipavatarImgV]; [youpaipavatarImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_offset(CGSizeMake(64.0f, 64.0f)); make.centerX.equalTo(bgV.mas_centerX); make.top.equalTo(subTitleL.mas_bottom).offset(25.0f); }]; UILabel *youpaipnicknameL = [[UILabel alloc] init]; youpaipnicknameL.font = LCFont16; youpaipnicknameL.textColor = HexColorFromRGB(0xffffff); youpaipnicknameL.text = self.youpaipmodel.youpaipanchor_name; [bgV addSubview:youpaipnicknameL]; self.youpaipnicknameL = youpaipnicknameL; [youpaipnicknameL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(youpaipavatarImgV.mas_bottom).offset(7.0f); make.centerX.equalTo(bgV.mas_centerX); }]; UIButton *youpaipfollowBtn = nil; if ([self.youpaipmodel.youpaipis_follow integerValue] == 0) { youpaipfollowBtn = [UIButton buttonWithType:UIButtonTypeCustom]; youpaipfollowBtn.titleLabel.font = LCFont17; youpaipfollowBtn.layer.cornerRadius = 24; youpaipfollowBtn.clipsToBounds = YES; [youpaipfollowBtn setTitle:@"关注" forState:0]; [youpaipfollowBtn addTarget:self action:@selector(youpaiffollowBtnClick) forControlEvents:UIControlEventTouchUpInside]; [youpaipfollowBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [youpaipfollowBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 120.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)]; [bgV addSubview:youpaipfollowBtn]; self.youpaipfollowBtn = youpaipfollowBtn; // [self reloadFollowBtnStyle]; [youpaipfollowBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(28.0f); make.right.offset(-28.0f); make.height.offset(48.0f); make.top.equalTo(youpaipnicknameL.mas_bottom).offset(20.0f); }]; } UIView *youpaiplineV = [[UIView alloc] init]; self.youpaiplineV = youpaiplineV; [youpaiplineV.layer addSublayer:[self youpaifdrawDashedLine]]; [bgV addSubview:youpaiplineV]; [youpaiplineV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(36.0f); make.right.offset(-36.0f); if (youpaipfollowBtn == nil) { make.top.equalTo(youpaipnicknameL.mas_bottom).offset(33.0f); }else{ make.top.equalTo(youpaipfollowBtn.mas_bottom).offset(33.0f); } make.height.offset(0.5f); }]; UILabel *youpaiprecommendL = [[UILabel alloc] init]; self.youpaiprecommendL =youpaiprecommendL; youpaiprecommendL.font = LCFont12; youpaiprecommendL.textColor = HexColorFromRGB(0x9F9DA5); youpaiprecommendL.backgroundColor = HexColorFromRGB(0x2A2935); youpaiprecommendL.text = @" 为您推荐,在线直播 "; [bgV addSubview:youpaiprecommendL]; [youpaiprecommendL mas_makeConstraints:^(MASConstraintMaker *make) { if (youpaipfollowBtn == nil) { make.top.equalTo(youpaipnicknameL.mas_bottom).offset(25.0f); }else{ make.top.equalTo(youpaipfollowBtn.mas_bottom).offset(25.0f); } make.centerX.equalTo(bgV.mas_centerX); }]; UIView *youpaiprecommendBgV = [[UIView alloc] init]; [bgV addSubview:youpaiprecommendBgV]; self.youpaiprecommendBgV = youpaiprecommendBgV; [youpaiprecommendBgV mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(bgV.mas_centerX); make.top.equalTo(youpaiprecommendL.mas_bottom).offset(25.0f); make.height.offset((KScreenWidth - 102.0f) / 3.0f); }]; UIButton *transformBtn = [UIButton buttonWithType:UIButtonTypeCustom]; self.youpaiptransformBtn = transformBtn; transformBtn.titleLabel.font = LCFont12; transformBtn.layer.cornerRadius = 13.0f; transformBtn.clipsToBounds = YES; [transformBtn setTitle:@"换一批" forState:0]; [transformBtn addTarget:self action:@selector(youpaiftransformBtnClick) forControlEvents:UIControlEventTouchUpInside]; [transformBtn setTitleColor:HexColorFromRGB(0xffffff) forState:UIControlStateNormal]; transformBtn.layer.borderColor = HexColorFromRGB(0xffffff).CGColor; transformBtn.layer.borderWidth = 0.5f; [bgV addSubview:transformBtn]; [transformBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.offset(-25.0f); make.centerX.equalTo(bgV.mas_centerX); make.top.equalTo(youpaiprecommendBgV.mas_bottom).offset(20.0f); make.size.mas_offset(CGSizeMake(69.0f, 26.0f)); }]; transformBtn.hidden = YES; [self youpaifcreateRecommendBtn]; } - (void)youpaifcreateRecommendBtn{ for (UIView *view in self.youpaiprecommendBgV.subviews) { [view removeFromSuperview]; } CGFloat width = (KScreenWidth - 102.0f) / 3.0f; if (self.youpaipmodel.youpaiplive.count<=0) { self.youpaiprecommendL.hidden = YES; self.youpaiptransformBtn.hidden = YES; self.youpaiplineV.hidden = YES; [self.youpaipfollowBtn mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.offset(28.0f); make.right.offset(-28.0f); make.height.offset(48.0f); make.top.equalTo(self.youpaipnicknameL.mas_bottom).offset(20.0f); make.bottom.offset(-25.0f); }]; }else{ self.youpaiprecommendL.hidden = NO; self.youpaiptransformBtn.hidden = NO; self.youpaiplineV.hidden = NO; [self.youpaipfollowBtn mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.offset(28.0f); make.right.offset(-28.0f); make.height.offset(48.0f); make.top.equalTo(self.youpaipnicknameL.mas_bottom).offset(20.0f); }]; } for (NSInteger i = 0; i < self.youpaipmodel.youpaiplive.count; i ++) { YOUPAILZLiveListItemModel *itemModel = self.youpaipmodel.youpaiplive[i]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.imageView.contentMode = UIViewContentModeScaleAspectFill; btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill; btn.contentVerticalAlignment = UIControlContentVerticalAlignmentFill; btn.layer.cornerRadius = 8.0f; btn.clipsToBounds = YES; btn.contentMode = UIViewContentModeScaleAspectFill; [btn sd_setImageWithURL:[LCTools getImageUrlWithAddress:itemModel.youpaipcover_img] forState:UIControlStateNormal]; btn.tag = i; [btn addTarget:self action:@selector(youpaifitemClick:) forControlEvents:UIControlEventTouchUpInside]; [self.youpaiprecommendBgV addSubview:btn]; [btn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(i * width + i * 4.0f); make.top.bottom.offset(0.0f); make.width.offset(width); if (i == self.youpaipmodel.youpaiplive.count - 1) { make.right.offset(0.0f); } }]; UIButton *youpaipleftTopBtn = [UIButton buttonWithType:UIButtonTypeCustom]; youpaipleftTopBtn.userInteractionEnabled = NO; youpaipleftTopBtn.frame = CGRectMake(0, 0, 41.0f, 14.0f); UIImage *bgImage = [LCTools ColorImage:youpaipleftTopBtn.mj_size FromColors:@[HexColorFromRGB(0xFF2ADD),HexColorFromRGB(0xFF6769)] ByGradientType:GradientLeftToRight]; [youpaipleftTopBtn setBackgroundImage:bgImage forState:UIControlStateNormal]; [youpaipleftTopBtn setBackgroundImage:bgImage forState:UIControlStateHighlighted]; [LCTools clipCorner:UIRectCornerBottomRight View:youpaipleftTopBtn size:CGSizeMake(8.0f, 8.0f)]; youpaipleftTopBtn.userInteractionEnabled = NO; [btn addSubview:youpaipleftTopBtn]; [youpaipleftTopBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.offset(0.0f); make.size.mas_offset(CGSizeMake(41.0f, 14.0f)); }]; NSString *path = [[NSBundle mainBundle] pathForResource:@"ic_live_zhibozhong_28" ofType:@"gif"]; YYAnimatedImageView *youpaipiconImgV = [[YYAnimatedImageView alloc] init]; youpaipiconImgV.image = [YYImage imageWithData:[NSData dataWithContentsOfFile:path]]; [youpaipleftTopBtn addSubview:youpaipiconImgV]; [youpaipiconImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(3.0f); make.centerY.equalTo(youpaipleftTopBtn.mas_centerY); make.size.mas_offset(CGSizeMake(9.5f, 9.5f)); }]; UILabel *youpaiptextL = [[UILabel alloc] init]; youpaiptextL.font = LCFont(8.0f); youpaiptextL.textColor = [UIColor whiteColor]; youpaiptextL.text = @"直播中"; [youpaipleftTopBtn addSubview:youpaiptextL]; [youpaiptextL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(youpaipiconImgV.mas_right).offset(1.5f); make.centerY.equalTo(youpaipleftTopBtn.mas_centerY); }]; UIView *footerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 20.0f)]; CAGradientLayer *gradientLayerBot = [CAGradientLayer layer]; gradientLayerBot.frame = footerV.bounds; //设置渐变颜色数组,可以加透明度的渐变 gradientLayerBot.colors = @[(__bridge id)[[UIColor whiteColor] colorWithAlphaComponent:0.0f].CGColor,(__bridge id)[[UIColor blackColor] colorWithAlphaComponent:0.1f].CGColor]; //设置渐变区域的起始和终止位置(范围为0-1) gradientLayerBot.startPoint = CGPointMake(0, 0.5f); gradientLayerBot.endPoint = CGPointMake(0, 1); [footerV.layer addSublayer:gradientLayerBot]; [btn addSubview:footerV]; [footerV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.bottom.right.offset(0.0f); make.height.offset(44.0f); }]; UILabel *youpaipnicknameL = [[UILabel alloc] init]; youpaipnicknameL.textColor = [UIColor whiteColor]; youpaipnicknameL.font = LCFont(10); youpaipnicknameL.text = itemModel.youpaipanchor_name; [footerV addSubview:youpaipnicknameL]; [youpaipnicknameL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(5.0f); make.bottom.offset(-3.0f); make.right.offset(-5.0f); }]; } } - (void)youpaiffollowBtnClick{ [self.youpaipfollowBtn setTitle:@"已关注" forState:UIControlStateNormal]; self.youpaipfollowBtn.userInteractionEnabled = NO; [self.youpaipfollowBtn setBackgroundImage:nil forState:(UIControlStateNormal)]; self.youpaipfollowBtn.backgroundColor = HexColorFromRGB(0xD8D8D8); [LCCommonHttp followUserId:self.youpaipmodel.youpaipanchor_id]; } - (void)youpaiftransformBtnClick{ @weakify(self); [LCHttpHelper requestWithURLString:GetUserCloseLive parameters:@{@"is_refresh_rand":@(1)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 YOUPAILZLiveCloseModel *model = [YOUPAILZLiveCloseModel mj_objectWithKeyValues:[dict objectForKey:@"data"]]; self.youpaipmodel = model; [self youpaifcreateRecommendBtn]; }else{ [ZCHUDHelper showTitle:[dict objectForKey:@"message"]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } - (void)youpaifitemClick:(UIButton *)sender{ if (self.youpaipitemClickBlock != nil) { self.youpaipitemClickBlock(self.youpaipmodel.youpaiplive[sender.tag]); } [self dismissViewControllerAnimated:NO completion:nil]; } - (void)youpaifcloseBtnClick{ if (self.youpaipcloseBlock != nil) { self.youpaipcloseBlock(); } [self dismissViewControllerAnimated:NO completion:nil]; } /// 虚线 - (CAShapeLayer *)youpaifdrawDashedLine{ CAShapeLayer *shapeLayer = [CAShapeLayer layer]; [shapeLayer setBounds:self.view.bounds]; [shapeLayer setPosition:self.view.center]; [shapeLayer setFillColor:[[UIColor clearColor] CGColor]]; // 设置虚线颜色为blackColor [shapeLayer setStrokeColor:[HexColorFromRGB(0x999999) CGColor]]; // 3.0f设置虚线的宽度 [shapeLayer setLineWidth:0.5f]; [shapeLayer setLineJoin:kCALineJoinRound]; // 3=线的宽度 1=每条线的间距 [shapeLayer setLineDashPattern: [NSArray arrayWithObjects:[NSNumber numberWithInt:5.0f], [NSNumber numberWithInt:1.0f],nil]]; // Setup the path CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, 0, 0); CGPathAddLineToPoint(path, NULL, KScreenWidth - 136.0f,0); [shapeLayer setPath:path]; CGPathRelease(path); return shapeLayer; } @end