HaveNewVersionView.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. //
  2. // HaveNewVersionView.m
  3. // VclustersGemini
  4. //
  5. // Created by APPLE on 2020/2/24.
  6. // Copyright © 2020 APPLE. All rights reserved.
  7. //
  8. #import "HaveNewVersionView.h"
  9. @interface HaveNewVersionView ()<UITableViewDelegate,UITableViewDataSource>
  10. @property (nonatomic,strong) NSMutableArray *dataSource;
  11. @end
  12. @implementation HaveNewVersionView
  13. @synthesize titleLabel;
  14. @synthesize detailLabel;
  15. @synthesize bgView;
  16. @synthesize deleteBtn;
  17. static HaveNewVersionView * _instance;
  18. + (instancetype)shardInstance {
  19. static dispatch_once_t HaveNewVersionViewonceToken;
  20. dispatch_once(&HaveNewVersionViewonceToken, ^{
  21. _instance = [[self alloc] init];
  22. });
  23. return _instance;
  24. }
  25. - (id)initWithFrame:(CGRect)frame
  26. {
  27. self = [super initWithFrame:frame];
  28. if (self)
  29. {
  30. [self drawAnyView];
  31. }
  32. return self;
  33. }
  34. - (void)drawAnyView
  35. {
  36. self.tag = 111111;
  37. [self setBackgroundColor:HW000000Color60];
  38. bgView = [[UIView alloc] init];
  39. [bgView setBackgroundColor:[UIColor whiteColor]];
  40. [bgView.layer setCornerRadius:8.f];
  41. [self addSubview:bgView];
  42. [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.height.mas_equalTo(328.f);
  44. make.width.mas_equalTo(300.f);
  45. make.centerX.equalTo(self.mas_centerX);
  46. make.centerY.equalTo(self.mas_centerY);
  47. }];
  48. // 图片
  49. UIImageView *topImageView = [[UIImageView alloc] init];
  50. topImageView.image = [UIImage imageNamed:@"gengxinbeijing_pic"];
  51. topImageView.contentMode = UIViewContentModeScaleAspectFit;
  52. [bgView addSubview:topImageView];
  53. [topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.top.mas_equalTo(bgView.mas_top);
  55. make.left.mas_equalTo(bgView.mas_left);
  56. make.right.mas_equalTo(bgView.mas_right);
  57. make.height.mas_equalTo(141);
  58. }];
  59. /*提示文字*/
  60. UILabel *tipsLabel = [[UILabel alloc] init];
  61. [tipsLabel setText:NSLocalizedString(@"app_update_new_version_tips",nil)];
  62. [tipsLabel setTextColor:HW0A132BColor];
  63. [tipsLabel setFont:[UIFont systemFontOfSize:14.f]];
  64. [tipsLabel setTextAlignment:(NSTextAlignmentCenter)];
  65. [tipsLabel setNumberOfLines:0];
  66. [bgView addSubview:tipsLabel];
  67. [tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.top.equalTo(topImageView.mas_bottom).offset(30.f);
  69. make.left.mas_equalTo(20);
  70. make.right.mas_equalTo(-20);
  71. make.height.mas_equalTo(60);
  72. }];
  73. /*删除按钮*/
  74. deleteBtn = [[UIButton alloc] init];
  75. [deleteBtn setBackgroundColor:[UIColor clearColor]];
  76. [deleteBtn setImage:[UIImage imageNamed:@"guanbi_bai_icon"] forState:(UIControlStateNormal)];
  77. [deleteBtn addTarget:self action:@selector(deleteBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
  78. [bgView addSubview:deleteBtn];
  79. [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.height.mas_equalTo(45.f);
  81. make.width.mas_equalTo(45.f);
  82. make.right.mas_equalTo(bgView.mas_right).mas_offset(0);
  83. make.top.mas_equalTo(bgView.mas_top).mas_offset(0);
  84. }];
  85. deleteBtn.hidden = YES;
  86. // 分割线
  87. UIView *line = [[UIView alloc] init];
  88. line.backgroundColor = HWCCCCCCColor;
  89. [bgView addSubview:line];
  90. [line mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.left.mas_equalTo(0);
  92. make.right.mas_equalTo(0);
  93. make.height.mas_equalTo(1);
  94. make.bottom.mas_equalTo(-92);
  95. }];
  96. // /*确定按钮*/
  97. // UIButton *okBtn = [[UIButton alloc] init];
  98. // [okBtn setBackgroundImage:[UIImage imageNamed:@"login_select_corner"] forState:(UIControlStateNormal)];
  99. // [okBtn setTitle:@"更新" forState:(UIControlStateNormal)];
  100. // [okBtn.titleLabel setFont:[UIFont systemFontOfSize:14.f]];
  101. // [okBtn addTarget:self action:@selector(updateBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
  102. // [okBtn.layer setCornerRadius:20.f];
  103. // okBtn.layer.masksToBounds = YES;
  104. // [bgView addSubview:okBtn];
  105. //
  106. // [okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  107. // make.height.mas_equalTo(40.f);
  108. // make.width.mas_equalTo(168.f);
  109. // make.centerX.equalTo(bgView.mas_centerX);
  110. // make.bottom.mas_equalTo(-20.f);
  111. // }];
  112. UIButton *updatekBtn = [[UIButton alloc] init];
  113. updatekBtn.frame = CGRectMake(0, 0, 160.f, 48.f);
  114. // gradient
  115. CAGradientLayer *gl = [CAGradientLayer layer];
  116. gl.frame = CGRectMake(0,0,160.f,48.f);
  117. gl.startPoint = CGPointMake(0, 0.5);
  118. gl.endPoint = CGPointMake(1, 0.5);
  119. gl.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor];
  120. gl.locations = @[@(0), @(1.0f)];
  121. [updatekBtn.layer addSublayer:gl];
  122. [updatekBtn addTarget:self action:@selector(updateBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
  123. [updatekBtn setTitle:NSLocalizedString(@"app_update_update",nil) forState:(UIControlStateNormal)];
  124. [updatekBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  125. [updatekBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
  126. [updatekBtn.layer setCornerRadius:8.f];
  127. updatekBtn.clipsToBounds = YES;
  128. [bgView addSubview:updatekBtn];
  129. [updatekBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  130. make.centerX.equalTo(bgView.mas_centerX);
  131. make.width.mas_equalTo(160.f);
  132. make.bottom.mas_equalTo(-20.f);
  133. make.height.mas_equalTo(48.f);
  134. }];
  135. // UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 1, 1) style:(UITableViewStylePlain)];
  136. // tableView.delegate = self;
  137. // tableView.dataSource = self;
  138. // [tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  139. // [tableView setSeparatorColor:[UIColor clearColor]];
  140. // [tableView setBackgroundColor:[UIColor clearColor]];
  141. // if (@available(iOS 15.0, *)) {
  142. // tableView.sectionHeaderTopPadding = 0;
  143. // }
  144. // [bgView addSubview:tableView];
  145. // [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  146. // make.left.mas_equalTo(0);
  147. // make.right.mas_equalTo(0);
  148. // make.top.mas_equalTo(topImageView.mas_bottom);
  149. // make.bottom.mas_equalTo(line.mas_top);
  150. // }];
  151. }
  152. - (void)deleteBtnPressed
  153. {
  154. [self removeFromSuperview];
  155. self.isShow = NO;
  156. if ([_delegate respondsToSelector:@selector(closeBtnBePressed)]) {
  157. [_delegate closeBtnBePressed];
  158. }
  159. }
  160. - (void)updateBtnPressed {
  161. if (!self.versionModel.necessary) { // 非强制更新
  162. self.isShow = NO;
  163. [self removeFromSuperview];
  164. if ([_delegate respondsToSelector:@selector(closeBtnBePressed)]) {
  165. [_delegate closeBtnBePressed];
  166. }
  167. }
  168. /*跳转蒲公英*/
  169. NSURL * url = [NSURL URLWithString:self.versionModel.downUrl];
  170. HLog(@"立即更新-跳转到:%@",self.versionModel.downUrl);
  171. // NSString *url = [self.versionModel.downUrl stringByReplacingOccurrencesOfString:@" " withString:@""]; // 防止url里有空格字符导致无法跳转
  172. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
  173. ;
  174. }];
  175. }
  176. #pragma mark - 列表委托
  177. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  178. return 1;
  179. }
  180. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  181. return self.dataSource.count;
  182. }
  183. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  184. static NSString *identifier = @"newVersionInfoCellidentifier";
  185. NSInteger row = indexPath.row;
  186. NSString *tipsString = self.dataSource[row];
  187. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  188. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  189. UITableViewCell *payTypecell = [tableView dequeueReusableCellWithIdentifier:identifier];
  190. payTypecell.selectionStyle = UITableViewCellSelectionStyleNone;
  191. if (!cell)
  192. {
  193. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  194. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  195. [cell setBackgroundColor:[UIColor clearColor]];
  196. /*文字*/
  197. [cell.textLabel setFont:[UIFont systemFontOfSize:14.f]];
  198. [cell.textLabel setTextColor:HWCFD1D4Color];
  199. cell.textLabel.numberOfLines = 0;
  200. [cell.textLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  201. make.left.mas_equalTo(15);
  202. make.right.mas_equalTo(-15);
  203. make.top.mas_equalTo(5);
  204. make.bottom.mas_equalTo(5);
  205. }];
  206. }
  207. cell.textLabel.text = [NSString stringWithFormat:@"·%@",tipsString];
  208. return cell;
  209. }
  210. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  211. return UITableViewAutomaticDimension;
  212. }
  213. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  214. UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 37)];
  215. bgView.backgroundColor = HWF5F7FAColor;
  216. UILabel *label1 = [[UILabel alloc] init];
  217. label1.text = [NSString stringWithFormat:@"发现新版本(%@)", self.versionModel.versionNumber];
  218. label1.textColor = HWCFD1D4Color;
  219. label1.font = [UIFont boldSystemFontOfSize:14.f];
  220. [bgView addSubview:label1];
  221. [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
  222. make.left.mas_equalTo(15);
  223. make.top.mas_equalTo(10);
  224. }];
  225. UILabel *label2 = [[UILabel alloc] init];
  226. label2.text = [NSString stringWithFormat:@"大小:%@MB", self.versionModel.fileSize];
  227. label2.textColor = HWF5F7FAColor;
  228. label2.font = [UIFont systemFontOfSize:10.f];
  229. [bgView addSubview:label2];
  230. [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
  231. make.left.mas_equalTo(label1.mas_right).mas_offset(5);
  232. make.centerY.mas_equalTo(label1.mas_centerY);
  233. }];
  234. return bgView;
  235. }
  236. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  237. return 35;
  238. }
  239. - (NSMutableArray *)dataSource {
  240. if (!_dataSource) {
  241. NSArray *tips = [self.versionModel.versionInfo componentsSeparatedByString:@"&&"];
  242. _dataSource = [NSMutableArray arrayWithArray:tips];
  243. }
  244. return _dataSource;
  245. }
  246. @end