// // SCLiveItemView.m // SellyCloudSDK_Example // // Created by Caleb on 21/7/25. // Copyright © 2025 Caleb. All rights reserved. // #import "SCLiveItemView.h" @interface SCLiveItemView () @property (nonatomic, strong)UIButton *btn; @property (nonatomic, strong)UIImageView *iconView; @property (nonatomic, strong)UILabel *titleLabel; @end @implementation SCLiveItemView - (instancetype)init { self = [super init]; if (self) { [self setupView]; } return self; } - (void)btnClick { // 添加触觉反馈 UIImpactFeedbackGenerator *feedback = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight]; [feedback impactOccurred]; // 添加动画效果 [UIView animateWithDuration:0.1 animations:^{ self.transform = CGAffineTransformMakeScale(0.95, 0.95); } completion:^(BOOL finished) { [UIView animateWithDuration:0.1 animations:^{ self.transform = CGAffineTransformIdentity; }]; }]; // 切换状态(只有直播的静音和摄像头按钮会自动切换状态) if (self.model.type == SCLiveItemTypeMute || self.model.type == SCLiveItemTypeCameraToggle) { self.model.isSelected = !self.model.isSelected; [self updateIconAndTitle]; } if (self.model.clickCallback) { self.model.clickCallback(); } } - (void)setupView { // 背景按钮(透明,用于接收点击) [self addSubview:self.btn]; [self.btn mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self); }]; // 图标 [self addSubview:self.iconView]; [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self).offset(8); make.centerX.equalTo(self); make.width.height.offset(32); }]; // 标题 [self addSubview:self.titleLabel]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.iconView.mas_bottom).offset(4); make.left.right.equalTo(self); make.height.offset(16); }]; } - (void)updateIconAndTitle { NSString *iconName = @""; NSString *title = @""; switch (self.model.type) { // ========== 直播推流 ========== case SCLiveItemTypeSwitchCamera: // 翻转摄像头 iconName = @"arrow.triangle.2.circlepath.camera"; title = @"翻转"; break; case SCLiveItemTypeMute: // 静音/取消静音(带状态切换) if (self.model.isSelected) { iconName = @"mic.slash.fill"; title = @"取消静音"; } else { iconName = @"mic.fill"; title = @"静音"; } break; case SCLiveItemTypeCameraToggle: // 摄像头开关 if (self.model.isSelected) { iconName = @"video.slash.fill"; title = @"开启摄像头"; } else { iconName = @"video.fill"; title = @"关闭摄像头"; } break; case SCLiveItemTypeCapture: // 截图(直播) iconName = @"camera.fill"; title = @"截图"; break; case SCLiveItemTypeBackgroundImage: // 背景图 iconName = @"photo.fill"; title = @"背景图"; break; // ========== 播放器 ========== case SCLiveItemTypePlayPause: // 播放/暂停 if (self.model.isSelected) { iconName = @"pause.circle.fill"; title = @"暂停"; } else { iconName = @"play.circle.fill"; title = @"播放"; } break; case SCLiveItemTypeVolume: // 音量控制 if (self.model.isSelected) { iconName = @"speaker.slash.fill"; title = @"取消静音"; } else { iconName = @"speaker.wave.3.fill"; title = @"静音"; } break; case SCLiveItemTypeScreenshot: // 截图(播放器) iconName = @"camera.fill"; title = @"截图"; break; case SCLiveItemTypeSeekForward: // 快进(播放器) iconName = @"goforward.10"; title = @"快进10秒"; break; case SCLiveItemTypeSettings: // 设置/重新配置 iconName = @"gearshape.fill"; title = @"设置"; break; case SCLiveItemTypePiP: // 设置/重新配置 iconName = @"pip"; title = @"画中画"; break; default: iconName = @"circle.fill"; title = @""; break; } UIImage *icon = [UIImage systemImageNamed:iconName]; self.iconView.image = icon; self.titleLabel.text = title; } - (void)setModel:(SCLiveItemModel *)model { _model = model; [self updateIconAndTitle]; } - (UIButton *)btn { if (!_btn) { _btn = [UIButton buttonWithType:UIButtonTypeCustom]; _btn.backgroundColor = [UIColor clearColor]; [_btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside]; } return _btn; } - (UIImageView *)iconView { if (!_iconView) { _iconView = [[UIImageView alloc] init]; _iconView.contentMode = UIViewContentModeScaleAspectFit; _iconView.tintColor = [UIColor whiteColor]; } return _iconView; } - (UILabel *)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc] init]; _titleLabel.textAlignment = NSTextAlignmentCenter; _titleLabel.font = [UIFont systemFontOfSize:11 weight:UIFontWeightMedium]; _titleLabel.textColor = [UIColor whiteColor]; } return _titleLabel; } @end