UpImageView.m 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. //
  2. // UpImageView.m
  3. // 乐销
  4. //
  5. // Created by 隋林栋 on 2016/12/28.
  6. // Copyright © 2016年 ping. All rights reserved.
  7. //
  8. #import "UpImageView.h"
  9. @interface UpImageView()
  10. @end
  11. @implementation UpImageView
  12. #pragma mark lazy init
  13. - (UIView *)upImageBG{
  14. if (_upImageBG == nil) {
  15. _upImageBG = [UIControl new];
  16. _upImageBG.tag = 1;
  17. _upImageBG.width = SCREEN_WIDTH;
  18. _upImageBG.clipsToBounds = true;
  19. // [_upImageBG addTarget:self action:@selector(showImage) forControlEvents:UIControlEventTouchUpInside];
  20. _upImageBG.widthHeight = XY(SCREEN_WIDTH,W(0));
  21. _upImageBG.backgroundColor = [UIColor clearColor];
  22. }
  23. return _upImageBG;
  24. }
  25. - (UIImageView *)upImageHead{
  26. if (_upImageHead == nil) {
  27. _upImageHead = [UIImageView new];
  28. _upImageHead.backgroundColor = [UIColor clearColor];
  29. _upImageHead.image = [UIImage imageNamed:@"spgl_tp"];
  30. _upImageHead.widthHeight = XY(W(17),W(17));
  31. }
  32. return _upImageHead;
  33. }
  34. - (UILabel *)upImageLabel{
  35. if (_upImageLabel == nil) {
  36. _upImageLabel = [UILabel new];
  37. [GlobalMethod setLabel:_upImageLabel widthLimit:0 numLines:0 fontNum:F(14) textColor:COLOR_LABEL text:@"添加图片(选填)"];
  38. }
  39. return _upImageLabel;
  40. }
  41. - (Collection_Image *)collection_Image{
  42. if (!_collection_Image) {
  43. _collection_Image = [Collection_Image new];
  44. _collection_Image.scrollDirection=UICollectionViewScrollDirectionVertical;
  45. WEAKSELF
  46. _collection_Image.blockUpComplete = ^(NSMutableArray *arr) {
  47. // NSMutableArray *ary = [NSMutableArray new];
  48. // dispatch_queue_t serialQueue=dispatch_queue_create("串行", DISPATCH_QUEUE_SERIAL);
  49. // dispatch_sync(serialQueue, ^{
  50. // for (int i =0; i<arr.count; i++) {
  51. // XG_AssetModel *model =arr[i];
  52. // NSLog(@"start %d",i);
  53. // sleep(i);
  54. // if (model.isPlaceholder==false) {
  55. // [[XG_AssetPickerManager manager] getPhotoWithAsset1:model.asset completion:^(UIImage *photo, NSDictionary *info) {
  56. // [ary addObject:photo];
  57. // }];
  58. // }
  59. // NSLog(@"end %d",i);
  60. // }
  61. // });
  62. // for (XG_AssetModel *model in arr) {
  63. // if (model.isPlaceholder==false) {
  64. // [[XG_AssetPickerManager manager] getPhotoWithAsset1:model.asset completion:^(UIImage *photo, NSDictionary *info) {
  65. // [ary addObject:photo];
  66. // }];
  67. // }
  68. // }
  69. weakSelf.imgArr = arr;
  70. if (weakSelf.blockResetView != nil) {
  71. [weakSelf resetView];
  72. if (weakSelf.blockResetView != nil) {
  73. weakSelf.blockResetView();
  74. }
  75. }
  76. };
  77. _collection_Image.blockDelComplete = ^(NSMutableArray *arr) {
  78. if (arr.count==1) {
  79. [weakSelf.imgArr removeAllObjects];
  80. }else{
  81. [weakSelf.imgArr removeAllObjects];
  82. weakSelf.imgArr = [NSMutableArray arrayWithCapacity:9];
  83. for (int j = 0; j < 9; j++) {
  84. [weakSelf.imgArr addObject:[NSNull null]];
  85. }
  86. for (int i =0; i<arr.count; i++) {
  87. XG_AssetModel *model =arr[i];
  88. if (model.asset) {
  89. [[XG_AssetPickerManager manager] getPhotoWithAsset1:model.asset completion:^(UIImage *photo, NSDictionary *info) {
  90. [weakSelf.imgArr replaceObjectAtIndex:model.number-1 withObject:photo];
  91. }];
  92. }
  93. }
  94. }
  95. };
  96. }
  97. return _collection_Image;
  98. }
  99. - (UILabel *)labelTitle{
  100. if (_labelTitle == nil) {
  101. _labelTitle = [UILabel new];
  102. [GlobalMethod setLabel:_labelTitle widthLimit:0 numLines:0 fontNum:F(16) textColor:COLOR_LABEL text:@""];
  103. _labelTitle.hidden=true;
  104. }
  105. return _labelTitle;
  106. }
  107. - (UILabel *)labelName{
  108. if (_labelName == nil) {
  109. _labelName = [UILabel new];
  110. [GlobalMethod setLabel:_labelName widthLimit:0 numLines:0 fontNum:F(14) textColor:COLOR_999 text:@""];
  111. _labelName.hidden=true;
  112. }
  113. return _labelName;
  114. }
  115. - (UILabel *)labelTipc{
  116. if (_labelTipc == nil) {
  117. _labelTipc = [UILabel new];
  118. [GlobalMethod setLabel:_labelTipc widthLimit:0 numLines:0 fontNum:F(13) textColor:COLOR_999 text:@""];
  119. _labelTipc.hidden=true;
  120. }
  121. return _labelTipc;
  122. }
  123. - (UIView *)backView{
  124. if (_backView == nil) {
  125. _backView = [UIView new];
  126. _backView.backgroundColor = COLOR_ADDRESS;
  127. [GlobalMethod setRoundView:_backView color:COLOR_ADDRESS numRound:5 width:0];
  128. _backView.hidden=true;
  129. }
  130. return _backView;
  131. }
  132. #pragma mark 初始化
  133. - (instancetype)init{
  134. self = [super init];
  135. if (self) {
  136. self.backgroundColor = [UIColor clearColor];
  137. self.width = SCREEN_WIDTH;
  138. self.isHiddenCollectionNoData = true;
  139. [self addSubview];
  140. }
  141. return self;
  142. }
  143. #pragma mark addSubView
  144. - (void)addSubview{
  145. [self addSubview:self.upImageBG];
  146. [self.upImageBG addSubview:self.upImageHead];
  147. [self.upImageBG addSubview:self.upImageLabel];
  148. [self addSubview:self.labelTitle];
  149. [self addSubview:self.labelName];
  150. [self addSubview:self.backView];
  151. [self.backView addSubview:self.labelTipc];
  152. [self addSubview:self.collection_Image];
  153. [self resetView];
  154. }
  155. - (void)resetView{
  156. [self removeSubViewWithTag:TAG_LINE];
  157. //see up image
  158. self.upImageBG.hidden = self.isNotShowUpImageView;
  159. self.collection_Image.hidden = true;
  160. if (self.isNotShowFileView) {
  161. self.labelTitle.hidden=false;
  162. self.labelName.hidden=false;
  163. self.backView.hidden=false;
  164. self.labelTipc.hidden=false;
  165. [self.labelTitle fitTitle:@"其他资质" variable:0];
  166. self.labelTitle.leftTop = XY(W(15),W(15));
  167. [self.labelName fitTitle:@"请上传你的其他认证资质(如需认证特定内容)" variable:0];
  168. self.labelName.leftTop = XY(W(15),self.labelTitle.bottom+W(10));
  169. self.collection_Image.top = self.labelName.bottom+W(10);
  170. self.collection_Image.left = W(5);
  171. self.collection_Image.hidden = self.collection_Image.aryDatas.count <= 0 && self.isHiddenCollectionNoData;
  172. if (self.isCreat) {
  173. _collection_Image.assets = self.assets;
  174. }
  175. [self.collection_Image resetView];
  176. self.backView.widthHeight = XY(SCREEN_WIDTH-W(30), W(100));
  177. self.backView.leftTop = XY(W(15),W(10)+self.collection_Image.aryDatas.count == 0 && self.isHiddenCollectionNoData?self.upImageBG.bottom:self.collection_Image.bottom);
  178. [self.labelTipc fitTitle:@"用户名称、认证信息需体现特定内容,请提供对应资质。 例如:网站需提供ICP备案查询截图、商标需提供商标注册证、手机应用需提供软件著作权证、游戏需提供版号、其他品牌授权文件等。" variable:self.backView.width-W(20)];
  179. self.labelTipc.leftTop = XY(W(10),W(10));
  180. self.backView.height = self.labelTipc.bottom+W(10);
  181. self.height = self.backView.bottom+W(10);
  182. }else{
  183. //up image top view
  184. self.upImageHead.leftTop = XY(W(15),W(15));
  185. self.upImageLabel.leftCenterY = XY(W(15),self.upImageHead.centerY);
  186. self.upImageBG.height = self.isNotShowUpImageTopView ? 0 : self.upImageHead.bottom + W(15);
  187. self.collection_Image.top = self.upImageBG.bottom;
  188. self.collection_Image.left = W(5);
  189. self.collection_Image.hidden = self.collection_Image.aryDatas.count <= 0 && self.isHiddenCollectionNoData;
  190. if (self.isCreat) {
  191. _collection_Image.assets = self.assets;
  192. }
  193. _collection_Image.imgName=self.imgName;
  194. [self.collection_Image resetView];
  195. self.height = self.collection_Image.aryDatas.count == 0 && self.isHiddenCollectionNoData?self.upImageBG.bottom:self.collection_Image.bottom;
  196. }
  197. }
  198. #pragma mark 显示图片
  199. - (void)showImage{
  200. [self.collection_Image showSelectImage];
  201. }
  202. #pragma mark 销毁
  203. - (void)dealloc{
  204. NSLog(@"%s %@",__func__,self.class);
  205. }
  206. @end