| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- //
- // MOTranslateSettingView.m
- // MiMoLive
- //
- // Created by SuperC on 2025/7/28.
- //
- #import "MOTranslateSettingView.h"
- #import "MOTranslateSettingCell.h"
- #import "MOTranslateSettingTypeTwoCell.h"
- #import "MOTranslateChooseView.h"
- #import "MOLangData.h"
- @interface MOTranslateSettingView ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, strong) UIView *bgView;
- @property (nonatomic, strong) UIButton *closeBtn;
- @property (nonatomic, strong) UILabel *titleLab;
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) MOTranslateChooseView *translateChooseView;//语言选择
- @property (nonatomic, strong) MOLangData *myLangData;//自己的语言设置
- @property (nonatomic, assign) BOOL theSwitchStatus;
- @end
- @implementation MOTranslateSettingView
- - (instancetype)init {
- if (self = [super init] ) {
- [self setupUI];
- }
- return self;
- }
- - (instancetype)initWithFrame:(CGRect)frame{
- self = [super initWithFrame:frame];
- if (self){
- [self setupUI];
- }
- return self;
- }
- - (void)setupUI{
- [self addSubview:self.bgView];
- [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(self).offset(0);
- make.left.right.equalTo(self);
- make.height.equalTo(@(198.0));
- }];
-
- [self.bgView addSubview:self.titleLab];
- [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.equalTo(self.bgView);
- make.height.equalTo(@52.0);
- }];
-
- [self.bgView addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.titleLab.mas_bottom);
- make.left.right.bottom.equalTo(self.bgView);
- }];
-
- [self addSubview:self.closeBtn];
- [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.right.equalTo(self);
- make.bottom.equalTo(self.bgView.mas_top);
- }];
- }
- - (void)toGetMyTranslationInfo{
- WEAKSELF
- [kHttpManager toGetTheTranslationInfoAboutMyWith:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- if(kCode_Success){
- MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
- weakSelf.myLangData = [MOLangData modelObjectWithDictionary:data[@"data"]];
- weakSelf.theSwitchStatus = weakSelf.myLangData.enabled;
- [weakSelf.tableView reloadData];
- }
- else{
- MOLogV(@"toGetTheTranslationInfoAboutMyWith 接口报错了");
- kShowNetError(data)
- }
- }];
- }
- #pragma mark - UITableViewDelegate,UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return 2;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- WEAKSELF
- if(indexPath.row == 0){
- MOTranslateSettingTypeTwoCell *cell = [tableView dequeueReusableCellWithIdentifier:MOTranslateSettingTypeTwoCell_ID];
- if (cell == nil){
- cell = [[MOTranslateSettingTypeTwoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MOTranslateSettingTypeTwoCell_ID];
- }
- cell.titleLab.text = NSLocalString(@"mimo_2_translate_show");
-
- cell.theSwitch.on = self.theSwitchStatus;
-
- cell.theSwitchChangeBlock = ^(UISwitch * _Nonnull theSwitch) {
-
- weakSelf.theSwitchStatus = theSwitch.on;
-
- if(weakSelf.myLangData.lang.length > 0){
- //设置打开或关闭
- [weakSelf toSetTranslationWith:weakSelf.myLangData And:theSwitch.on];
- }
- else{
- [weakSelf.tableView reloadData];
- }
- };
-
- return cell;
- }
- else{
- MOTranslateSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:MOTranslateSettingCell_ID];
- if (cell == nil){
- cell = [[MOTranslateSettingCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MOTranslateSettingCell_ID];
- }
- cell.titleLab.text = NSLocalString(@"mimo_2_translate_choose");
-
- if(self.myLangData.name.length > 0){
- cell.contentLab.text = self.myLangData.name;
- }
- else{
- cell.contentLab.text = NSLocalString(@"mimo_2_translate_choose_null");
- }
-
- if(self.theSwitchStatus){
- cell.titleLab.alpha = 1.0;
- cell.contentLab.alpha = 1.0;
- }
- else{
- cell.titleLab.alpha = 0.3;
- cell.contentLab.alpha = 0.3;
- }
-
- return cell;
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
-
- WEAKSELF
- if(indexPath.row == 1 && self.theSwitchStatus){
- //选择语言
- if(self.translateChooseView){
- self.translateChooseView.hidden = NO;
- if(self.myLangData.lang.length > 0){
- self.translateChooseView.lang = self.myLangData.lang;
- }
- [self.translateChooseView showTranslateChooseView];
- return;
- }
-
- self.translateChooseView = [[MOTranslateChooseView alloc] init];
- if(self.myLangData.lang.length > 0){
- self.translateChooseView.lang = self.myLangData.lang;
- }
- [self addSubview:self.translateChooseView];
- [self.translateChooseView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self);
- }];
- [self.translateChooseView showTranslateChooseView];
- self.translateChooseView.cellSelectBlock = ^(MOLangData * _Nonnull langData) {
- [weakSelf toSetTranslationWith:langData And:weakSelf.theSwitchStatus];
- };
- }
- }
- - (void)toSetTranslationWith:(MOLangData *)langData And:(BOOL)enabled{
- WEAKSELF
- NSString *langStr = langData.lang;
- if(langData.lang.length == 0){
- return;
- }
-
- NSDictionary *dict = @{@"lang":langStr,@"enabled":@(enabled)};
- [kHttpManager toSettingTheTranslationConfigWith:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- weakSelf.myLangData.lang = langStr;
- weakSelf.myLangData.name = langData.name;
- if(kCode_Success){
- [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_common_success")];
- weakSelf.myLangData.enabled = enabled;
- }
- else{
- MOLogV(@"toSettingTheTranslationConfigWith 接口报错了");
- kShowNetError(data)
- weakSelf.myLangData.enabled = !enabled;
- }
- weakSelf.theSwitchStatus = weakSelf.myLangData.enabled;
- weakSelf.theSettingChangeBlock ? weakSelf.theSettingChangeBlock(weakSelf.myLangData) : nil;
- [weakSelf.tableView reloadData];
- }];
- }
- - (void)showTranslateSettingView{
- [self toGetMyTranslationInfo];
-
- self.frame = CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT);
-
- CGRect actionViewRect = self.bgView.frame;
- actionViewRect.origin.y = SCREENHEIGHT;
- self.bgView.frame = actionViewRect;
-
- WEAKSELF
- [UIView animateWithDuration:0.3 animations:^{
- CGRect actionViewRect = weakSelf.bgView.frame;
- actionViewRect.origin.y = SCREENHEIGHT - 198.0;
- weakSelf.bgView.frame = actionViewRect;
- }];
-
- //不能滑动
- SendNotification(@"MOShowLivePagesVCCannotScroll")
- }
- - (void)dismissTranslateSettingView{
- //完成下移动画
- WEAKSELF
- [UIView animateWithDuration:0.3 animations:^
- {
- CGRect actionSheetViewRect = weakSelf.bgView.frame;
- actionSheetViewRect.origin.y = SCREENHEIGHT;
- weakSelf.bgView.frame = actionSheetViewRect;
- } completion:^(BOOL finished)
- {
- [self removeFromSuperview];
- }];
-
- //可以滑动
- SendNotification(@"MOShowLivePagesVCCanScroll")
- }
- #pragma mark - Lazy
- - (UIView *)bgView{
- if(!_bgView){
- _bgView = [[UIView alloc] init];
- _bgView.backgroundColor = [MOTools colorWithHexString:@"#FFFFFF"];
- _bgView.layer.cornerRadius = 16.0;
- _bgView.layer.masksToBounds = YES;
- _bgView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
- }
- return _bgView;
- }
- - (UILabel *)titleLab{
- if(!_titleLab)
- {
- _titleLab = [UILabel new];
- _titleLab.textColor = kBaseTextColor_1;
- _titleLab.textAlignment = NSTextAlignmentCenter;
- _titleLab.font = [MOTextTools semiboldFont:16.0];
- _titleLab.backgroundColor = [UIColor clearColor];
- _titleLab.text = NSLocalString(@"mimo_2_translate_set");
- }
- return _titleLab;
- }
- - (UITableView *)tableView{
- if (!_tableView)
- {
- _tableView= [[UITableView alloc] init];
- if (@available(iOS 11.0, *))
- {
- _tableView.estimatedRowHeight = 0;
- _tableView.estimatedSectionFooterHeight = 0;
- _tableView.estimatedSectionHeaderHeight = 0;
- _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }
-
- //iOS15适配
- if (@available(iOS 15.0, *))
- {
- self.tableView.sectionHeaderTopPadding = 0;
- }
-
- _tableView.backgroundColor = [UIColor clearColor];
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.dataSource = self;
- _tableView.delegate = self;
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.showsHorizontalScrollIndicator = NO;
- _tableView.rowHeight = 52.0;
-
- [_tableView registerClass:[MOTranslateSettingCell class] forCellReuseIdentifier:MOTranslateSettingCell_ID];
- [_tableView registerClass:[MOTranslateSettingTypeTwoCell class] forCellReuseIdentifier:MOTranslateSettingTypeTwoCell_ID];
- }
- return _tableView;
- }
- - (UIButton *)closeBtn{
- if(!_closeBtn){
- _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_closeBtn setTitle:@"" forState:UIControlStateNormal];
- [_closeBtn addTarget:self action:@selector(closeBtnClickAction) forControlEvents:UIControlEventTouchUpInside];
- }
- return _closeBtn;
- }
- - (void)closeBtnClickAction{
- [self dismissTranslateSettingView];
- }
- @end
|