123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- //
- // YOUPAILZAnchorMenuView.m
- // TIANYAN
- //
- // Created by CY on 2021/5/21.
- // Copyright © 2021 leo. All rights reserved.
- //
- #import "YOUPAILZAnchorMenuView.h"
- static NSInteger const youpaipROWCOUNT = 4;
- @interface YOUPAILZAnchorMenuView ()
- @property (nonatomic, strong) UIView *youpaipsupView;
- @property (nonatomic, weak) UIScrollView *youpaipscrollView;
- @property (nonatomic, strong) NSMutableArray <UIImageView *>* youpaipimgVs;
- @end
- @implementation YOUPAILZAnchorMenuView
- - (instancetype)initWithSupView:(UIView *)view{
- if (self = [super init]) {
- _youpaipsupView = view;
- self.frame = _youpaipsupView.bounds;
- self.hidden = YES;
- [self youpaifinitUI];
-
- [_youpaipsupView addSubview:self];
- }
- return self;
- }
- - (void)youpaifinitUI{
-
- CGFloat totalHeight = [self youpaiftotalHeight];
-
- UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, self.mj_h - totalHeight - SafeHeight, self.mj_w, totalHeight + SafeHeight)];
- scrollView.backgroundColor = HexColorFromRGB(0x2A2935);
- [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:scrollView size:CGSizeMake(20.0f, 20.0f)];
- scrollView.showsVerticalScrollIndicator = NO;
- scrollView.showsHorizontalScrollIndicator = NO;
- [self addSubview:scrollView];
- self.youpaipscrollView = scrollView;
-
- CGFloat width = KScreenWidth / youpaipROWCOUNT;
- CGFloat height = 60.0f;
- for (NSInteger i = 0; i < self.arr.count; i ++) {
-
- NSDictionary *dict = self.arr[i];
-
- NSInteger row = i / youpaipROWCOUNT;
- NSInteger col = i % youpaipROWCOUNT;
-
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- btn.frame = CGRectMake(col * width, 28.0f + row * height + row * 10.0f, width, height);
- btn.tag = i;
- [btn addTarget:self action:@selector(youpaifbtnClick:) forControlEvents:UIControlEventTouchUpInside];
- [scrollView addSubview:btn];
-
- UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake((width - 42.0f) / 2.0f, 0, 42.0f, 42.0f)];
- imageV.image = dict[@"image"];
- [btn addSubview:imageV];
- [self.youpaipimgVs addObject:imageV];
-
- UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, imageV.mj_h + 5.0f, btn.mj_w, btn.mj_h - (imageV.mj_h + 5.0f))];
- lab.font = LCFont(10.0f);
- lab.textColor = HexColorFromRGB(0xAAAAAA);
- lab.textAlignment = NSTextAlignmentCenter;
- lab.text = dict[@"title"];
- [btn addSubview:lab];
- }
- }
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
- UITouch* touch = [touches anyObject];
- UIView* view = [touch view];
- if (view != self.youpaipscrollView) {
- [self youpaifhiddenAnimation];
- }
- }
- - (void)youpaifbtnClick:(UIButton *)sender{
- sender.selected = !sender.selected;
- NSDictionary *dict = self.arr[sender.tag];
- NSString *type = dict[@"type"];
- UIImage *image = sender.selected ? dict[@"selImage"] : dict[@"image"];
- UIImageView *imgV = self.youpaipimgVs[sender.tag];
- imgV.image = image;
- if ([type isEqual:@"remove_screen"]) {
- if (self.youpaiphideChatMessageBlock != nil) {
- self.youpaiphideChatMessageBlock();
- }
- }else if ([type isEqual:@"font_size"]) {
- if (self.youpaipreplaceChatMessageFontSizeBlock != nil) {
- self.youpaipreplaceChatMessageFontSizeBlock();
- }
- }else if ([type isEqual:@"voice"]) {
- if (self.youpaipcloseVoiceBlock != nil) {
- self.youpaipcloseVoiceBlock(sender.selected);
- }
- }else if ([type isEqual:@"change_camera"]) {
- if (self.youpaipchangeCameraBlock != nil) {
- self.youpaipchangeCameraBlock();
- }
- }else if ([type isEqual:@"anchor_beauty"]) {
- if (self.youpaipbeautyBlock != nil) {
- self.youpaipbeautyBlock();
- }
- }else if ([type isEqual:@"anchor_close"]) {
- if (self.youpaipcloseBlock != nil) {
- self.youpaipcloseBlock();
- }
- }else if ([type isEqual:@"bg_music"]) {
- if (self.showMusicBlock != nil) {
- self.showMusicBlock();
- }
- }else if ([type isEqual:@"member_manage"]) {
- if (self.showMemberManage != nil) {
- self.showMemberManage();
- }
- }
- [self youpaifhiddenAnimation];
- }
- - (void)youpaifshowAnimation{
- self.hidden = NO;
- CGFloat height = [self youpaiftotalHeight];
-
- self.youpaipscrollView.frame = CGRectMake(0, self.mj_h, self.mj_w, height + SafeHeight);
- [UIView animateWithDuration:0.25f animations:^{
- self.youpaipscrollView.frame = CGRectMake(0, self.mj_h - height - SafeHeight, self.mj_w, height + SafeHeight);
- }];
- }
- - (void)youpaifhiddenAnimation{
- CGFloat height = [self youpaiftotalHeight];
- self.youpaipscrollView.frame = CGRectMake(0, self.mj_h - height - SafeHeight, self.mj_w, height + SafeHeight);
- [UIView animateWithDuration:0.25f animations:^{
- self.youpaipscrollView.frame = CGRectMake(0, self.mj_h, self.mj_w, height + SafeHeight);
- } completion:^(BOOL finished) {
- if (finished) {
- self.hidden = YES;
- }
- }];
- }
- - (CGFloat)youpaiftotalHeight{
- NSInteger row = (self.arr.count + youpaipROWCOUNT - 1) / youpaipROWCOUNT;
- CGFloat height = 56.0f + (row * 60.0f) + ((row - 1) * 10.0f);
- return height;
- }
- - (NSMutableArray<UIImageView *> *)youpaipimgVs{
- if (!_youpaipimgVs) {
- _youpaipimgVs = [[NSMutableArray alloc] init];
- }
- return _youpaipimgVs;
- }
- - (NSArray *)arr{
- return @[
- @{@"title":@"美颜",@"image":[UIImage imageNamed:@"vqu_images_L_live_anchor_beauty"],@"selImage":[UIImage imageNamed:@"vqu_images_L_live_anchor_beauty"],@"type":@"anchor_beauty"},
- // @{@"title":@"背景音乐",@"image":[UIImage imageNamed:@"vqu_images_L_live_anchor_bg_music"],@"selImage":[UIImage imageNamed:@"vqu_images_L_live_anchor_bg_music"],@"type":@"bg_music"},
- @{@"title":@"清屏",@"image":[UIImage imageNamed:@"vqu_images_L_live_remove_screen"],@"selImage":[UIImage imageNamed:@"vqu_images_L_live_remove_screen"],@"type":@"remove_screen"},
- @{@"title":@"成员管理",@"image":[UIImage imageNamed:@"vqu_images_L_live_member_manage"],@"selImage":[UIImage imageNamed:@"vqu_images_L_live_member_manage"],@"type":@"member_manage"},
- @{@"title":@"镜头切换",@"image":[UIImage imageNamed:@"vqu_images_L_live_change_camera-1"],@"selImage":[UIImage imageNamed:@"vqu_images_L_live_change_camera-1"],@"type":@"change_camera"},
- @{@"title":@"静音",@"image":[UIImage imageNamed:@"vqu_images_L_live_voice"],@"selImage":[UIImage imageNamed:@"vqu_images_L_live_voice_close"],@"type":@"voice"},
- // @{@"title":@"大字幕",@"image":[UIImage imageNamed:@"vqu_images_L_live_font_size"],@"selImage":[UIImage imageNamed:@"vqu_images_L_live_font_size"],@"type":@"font_size"},
-
- ];
- }
- @end
|