// // 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)setVersionModel:(HWVersionModel *)versionModel { _versionModel = versionModel; [self drawAnyView]; } - (void)drawAnyView { if(bgView){ [bgView removeFromSuperview]; } self.tag = 111111; [self setBackgroundColor:HW000000Color60]; NSString *tipStr = _versionModel.versionInfo; CGFloat curHeight = [tipStr boundingRectWithSize:CGSizeMake(300 -40, 1000) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.0]} context:nil].size.height; CGFloat fullHeight = curHeight + 20; BOOL isNeedScroll = NO; curHeight += 10; if( (curHeight + 380) >= SCREEN_H){ curHeight = SCREEN_H - 380 - 10; isNeedScroll = YES; } bgView = [[UIView alloc] init]; [bgView setBackgroundColor:[UIColor whiteColor]]; [bgView.layer setCornerRadius:8.f]; [self addSubview:bgView]; [bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(280.f + curHeight); make.width.mas_equalTo(300.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(141); }]; /*提示文字*/ UILabel *tipsLabel = [[UILabel alloc] init]; //[tipsLabel setText:NSLocalizedString(@"app_update_new_version_tips",nil)]; [tipsLabel setText:tipStr]; [tipsLabel setTextColor:HW0A132BColor]; [tipsLabel setFont:[UIFont systemFontOfSize:13.f]]; //[tipsLabel setTextAlignment:(NSTextAlignmentCenter)]; [tipsLabel setNumberOfLines:0]; // [bgView addSubview:tipsLabel]; // [tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(topImageView.mas_bottom).offset(20.f); // make.left.mas_equalTo(20); // make.right.mas_equalTo(-20); // make.height.mas_equalTo(curHeight); // }]; //可能文字超出 UIScrollView *bgScorllV = [[UIScrollView alloc] init]; //bgScorllV.showsHorizontalScrollIndicator = NO; //bgScorllV.backgroundColor = [UIColor greenColor]; if(isNeedScroll){ [bgView addSubview:bgScorllV]; [bgScorllV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(topImageView.mas_bottom).offset(20.f); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.height.mas_equalTo(curHeight); }]; [bgScorllV addSubview:tipsLabel]; [tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.left.mas_equalTo(20); //make.right.mas_equalTo(-20); make.width.mas_equalTo(260); make.height.mas_equalTo(fullHeight); }]; bgScorllV.contentSize = CGSizeMake(300, fullHeight); } else{ [bgView addSubview:tipsLabel]; [tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(topImageView.mas_bottom).offset(20.f); make.left.mas_equalTo(20); make.right.mas_equalTo(-20); make.height.mas_equalTo(curHeight); }]; } /*删除按钮*/ deleteBtn = [[UIButton alloc] init]; [deleteBtn setBackgroundColor:[UIColor clearColor]]; //[deleteBtn setImage:[UIImage imageNamed:@"guanbi_bai_icon"] forState:(UIControlStateNormal)]; [deleteBtn setImage:[UIImage imageNamed:@"common_del"] 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 = HWCCCCCCColor; // [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(-92); // }]; // gradient CAGradientLayer *gl = [CAGradientLayer layer]; gl.frame = CGRectMake(0,0,160.f,40.f); gl.startPoint = CGPointMake(0, 0.5); gl.endPoint = CGPointMake(1, 0.5); gl.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor]; gl.locations = @[@(0), @(1.0f)]; if(_versionModel.necessary){ UIButton *updatekBtn = [[UIButton alloc] init]; updatekBtn.frame = CGRectMake(0, 0, 160.f, 40.f); [updatekBtn.layer addSublayer:gl]; [updatekBtn addTarget:self action:@selector(updateBtnPressed) forControlEvents:(UIControlEventTouchUpInside)]; [updatekBtn setTitle:NSLocalizedString(@"app_update_update",nil) forState:(UIControlStateNormal)]; [updatekBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)]; [updatekBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]]; [updatekBtn.layer setCornerRadius:8.f]; updatekBtn.clipsToBounds = YES; [bgView addSubview:updatekBtn]; [updatekBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(bgView.mas_centerX); make.width.mas_equalTo(160.f); make.bottom.mas_equalTo(-30.f); make.height.mas_equalTo(40.f); }]; } else{ /*稍后再说 按钮 app_update_wait*/ UIButton *waitBtn = [[UIButton alloc] init]; [waitBtn setTitle:NSLocalizedString(@"app_update_wait",nil) forState:(UIControlStateNormal)]; [waitBtn setTitleColor:HW666666Color forState:UIControlStateNormal]; [waitBtn.titleLabel setFont:[UIFont systemFontOfSize:14.f]]; [waitBtn addTarget:self action:@selector(waitBtnPressed) forControlEvents:(UIControlEventTouchUpInside)]; [bgView addSubview:waitBtn]; [waitBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(30.f); make.width.mas_equalTo(168.f); make.centerX.equalTo(bgView.mas_centerX); make.bottom.mas_equalTo(-20.f); }]; UIButton *updatekBtn = [[UIButton alloc] init]; updatekBtn.frame = CGRectMake(0, 0, 160.f, 40.f); [updatekBtn.layer addSublayer:gl]; [updatekBtn addTarget:self action:@selector(updateBtnPressed) forControlEvents:(UIControlEventTouchUpInside)]; [updatekBtn setTitle:NSLocalizedString(@"app_update_update",nil) forState:(UIControlStateNormal)]; [updatekBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)]; [updatekBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]]; [updatekBtn.layer setCornerRadius:8.f]; updatekBtn.clipsToBounds = YES; [bgView addSubview:updatekBtn]; [updatekBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(bgView.mas_centerX); make.width.mas_equalTo(160.f); make.bottom.equalTo(waitBtn.mas_top).offset(-10); make.height.mas_equalTo(40.f); }]; } } - (void)waitBtnPressed { [self deleteBtnPressed]; if(_versionModel.versionNumber){ [HWDataManager setObjectWithKey:Const_did_show_version_and_click_wait value:_versionModel.versionNumber]; } } - (void)deleteBtnPressed { [self removeFromSuperview]; self.isShow = NO; if ([_delegate respondsToSelector:@selector(closeBtnBePressed)]) { [_delegate closeBtnBePressed]; } if(_closeViewFun){ _closeViewFun(); } } - (void)updateBtnPressed { if (!self.versionModel.necessary) { // 非强制更新 self.isShow = NO; [self removeFromSuperview]; if ([_delegate respondsToSelector:@selector(closeBtnBePressed)]) { [_delegate closeBtnBePressed]; } } /*跳转蒲公英*/ NSURL * url = [NSURL URLWithString:self.versionModel.downUrl]; 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