// // HaveNewVersionView.m // VclustersGemini // // Created by APPLE on 2020/2/24. // Copyright © 2020 APPLE. All rights reserved. // #import "HaveNewVersionView.h" @interface HaveNewVersionView () @property (nonatomic,strong) NSMutableArray *dataSource; @end @implementation HaveNewVersionView @synthesize titleLabel; @synthesize detailLabel; @synthesize bgView; @synthesize deleteBtn; static HaveNewVersionView * _instance; + (instancetype)shardInstance { static dispatch_once_t HaveNewVersionViewonceToken; dispatch_once(&HaveNewVersionViewonceToken, ^{ _instance = [[self alloc] init]; }); return _instance; } - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self drawAnyView]; } return self; } - (void)drawAnyView { self.tag = 111111; [self setBackgroundColor:[UIColor clearColor]]; bgView = [[UIView alloc] init]; [bgView setBackgroundColor:HWF5F7FAColor]; [bgView.layer setCornerRadius:20.f]; [self addSubview:bgView]; [bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(320.f); make.width.mas_equalTo(260.f); make.centerX.equalTo(self.mas_centerX); make.centerY.equalTo(self.mas_centerY); }]; // 图片 UIImageView *topImageView = [[UIImageView alloc] init]; topImageView.image = [UIImage imageNamed:@"gengxinbeijing_pic"]; topImageView.contentMode = UIViewContentModeScaleAspectFit; [bgView addSubview:topImageView]; [topImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(bgView.mas_top); make.left.mas_equalTo(bgView.mas_left); make.right.mas_equalTo(bgView.mas_right); make.height.mas_equalTo(134); }]; /*删除按钮*/ deleteBtn = [[UIButton alloc] init]; [deleteBtn setBackgroundColor:[UIColor clearColor]]; [deleteBtn setImage:[UIImage imageNamed:@"guanbi_bai_icon"] forState:(UIControlStateNormal)]; [deleteBtn addTarget:self action:@selector(deleteBtnPressed) forControlEvents:(UIControlEventTouchUpInside)]; [bgView addSubview:deleteBtn]; [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(45.f); make.width.mas_equalTo(45.f); make.right.mas_equalTo(bgView.mas_right).mas_offset(0); make.top.mas_equalTo(bgView.mas_top).mas_offset(0); }]; // deleteBtn.hidden = YES; // 分割线 UIView *line = [[UIView alloc] init]; line.backgroundColor = HW666666Color; [bgView addSubview:line]; [line mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.height.mas_equalTo(1); make.bottom.mas_equalTo(-70); }]; /*确定按钮*/ UIButton *okBtn = [[UIButton alloc] init]; [okBtn setBackgroundImage:[UIImage imageNamed:@"login_select_corner"] forState:(UIControlStateNormal)]; [okBtn setTitle:@"下载更新" forState:(UIControlStateNormal)]; [okBtn.titleLabel setFont:[UIFont systemFontOfSize:14.f]]; [okBtn addTarget:self action:@selector(updateBtnPressed) forControlEvents:(UIControlEventTouchUpInside)]; [okBtn.layer setCornerRadius:20.f]; okBtn.layer.masksToBounds = YES; [bgView addSubview:okBtn]; [okBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(40.f); make.width.mas_equalTo(168.f); make.centerX.equalTo(bgView.mas_centerX); make.bottom.mas_equalTo(-20.f); }]; UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 1, 1) style:(UITableViewStylePlain)]; tableView.delegate = self; tableView.dataSource = self; [tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)]; [tableView setSeparatorColor:[UIColor clearColor]]; [tableView setBackgroundColor:[UIColor clearColor]]; if (@available(iOS 15.0, *)) { tableView.sectionHeaderTopPadding = 0; } [bgView addSubview:tableView]; [tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.mas_equalTo(topImageView.mas_bottom); make.bottom.mas_equalTo(line.mas_top); }]; } - (void)deleteBtnPressed { [self removeFromSuperview]; self.isShow = NO; if ([_delegate respondsToSelector:@selector(closeBtnBePressed)]) { [_delegate closeBtnBePressed]; } } - (void)updateBtnPressed { if (!self.versionModel.necessary) { // 非强制更新 self.isShow = NO; [self removeFromSuperview]; if ([_delegate respondsToSelector:@selector(closeBtnBePressed)]) { [_delegate closeBtnBePressed]; } } // NSString *fileKey = FileAPPManifestKey; // NSString *appID = [[NSBundle mainBundle] bundleIdentifier]; // if ([appID containsString:@"com.kxly.cloudgame"]){ // fileKey = @"LowLevelMultipartUpload_25944032109132595200"; // } // // NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:@"itms-services://?action=download-manifest&url=https://file.phone.androidscloud.com:8121/document/newFile/download/1/%@/%@/manifest.plist",Const_File_Access_Key,fileKey]]; // //// HLog(@"立即更新-跳转到:%@",self.versionModel.downUrl); //// NSString *url = [self.versionModel.downUrl stringByReplacingOccurrencesOfString:@" " withString:@""]; // 防止url里有空格字符导致无法跳转 // [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) { // ; // }]; } #pragma mark - 列表委托 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.dataSource.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *identifier = @"newVersionInfoCellidentifier"; NSInteger row = indexPath.row; NSString *tipsString = self.dataSource[row]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; cell.selectionStyle = UITableViewCellSelectionStyleNone; UITableViewCell *payTypecell = [tableView dequeueReusableCellWithIdentifier:identifier]; payTypecell.selectionStyle = UITableViewCellSelectionStyleNone; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier]; [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; [cell setBackgroundColor:[UIColor clearColor]]; /*文字*/ [cell.textLabel setFont:[UIFont systemFontOfSize:14.f]]; [cell.textLabel setTextColor:HWCFD1D4Color]; cell.textLabel.numberOfLines = 0; [cell.textLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.right.mas_equalTo(-15); make.top.mas_equalTo(5); make.bottom.mas_equalTo(5); }]; } cell.textLabel.text = [NSString stringWithFormat:@"·%@",tipsString]; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewAutomaticDimension; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 37)]; bgView.backgroundColor = HWF5F7FAColor; UILabel *label1 = [[UILabel alloc] init]; label1.text = [NSString stringWithFormat:@"发现新版本(%@)", self.versionModel.versionNumber]; label1.textColor = HWCFD1D4Color; label1.font = [UIFont boldSystemFontOfSize:14.f]; [bgView addSubview:label1]; [label1 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.top.mas_equalTo(10); }]; UILabel *label2 = [[UILabel alloc] init]; label2.text = [NSString stringWithFormat:@"大小:%@MB", self.versionModel.fileSize]; label2.textColor = HWF5F7FAColor; label2.font = [UIFont systemFontOfSize:10.f]; [bgView addSubview:label2]; [label2 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(label1.mas_right).mas_offset(5); make.centerY.mas_equalTo(label1.mas_centerY); }]; return bgView; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 35; } - (NSMutableArray *)dataSource { if (!_dataSource) { NSArray *tips = [self.versionModel.versionInfo componentsSeparatedByString:@"&&"]; _dataSource = [NSMutableArray arrayWithArray:tips]; } return _dataSource; } @end