ImagePickerCollectionCell.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. //
  2. // ImagePickerCollectionCell.m
  3. // 乐销
  4. //
  5. // Created by 隋林栋 on 2017/4/6.
  6. // Copyright © 2017年 ping. All rights reserved.
  7. //
  8. #import "ImagePickerCollectionCell.h"
  9. // imagecontrol
  10. #import "ImageControl.h"
  11. @implementation ImagePickerCollectionCell
  12. #pragma mark 懒加载
  13. - (PHImageRequestOptions *)opt{
  14. if (!_opt) {
  15. _opt = [[PHImageRequestOptions alloc]init];
  16. _opt.resizeMode = PHImageRequestOptionsResizeModeFast;
  17. _opt.synchronous = YES;
  18. _opt.deliveryMode = PHImageRequestOptionsDeliveryModeOpportunistic;
  19. }
  20. return _opt;
  21. }
  22. - (PHImageManager *)imageManager{
  23. if (!_imageManager) {
  24. _imageManager = [[PHImageManager alloc] init];
  25. }
  26. return _imageManager;
  27. }
  28. - (UIImageView *)iconImg{
  29. if (_iconImg == nil) {
  30. _iconImg = [UIImageView new];
  31. CGFloat width = (SCREEN_WIDTH - W(5)*4)/3.0 - 1;
  32. _iconImg.widthHeight = XY(width,width);
  33. _iconImg.contentMode = UIViewContentModeScaleAspectFill;
  34. _iconImg.clipsToBounds = true;
  35. }
  36. return _iconImg;
  37. }
  38. - (ImageControl *)rightButton{
  39. if (_rightButton == nil) {
  40. _rightButton = [ImageControl initWithFrame:CGRectMake(0, 0, 0, 0) imageName:@"Not to choose" heightImageName:@"choose" imageFrame:CGRectMake(0, 0, W(20), W(20)) tag:1];
  41. [_rightButton addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  42. }
  43. return _rightButton;
  44. }
  45. #pragma mark 初始化
  46. - (instancetype)initWithFrame:(CGRect)frame{
  47. self = [super initWithFrame:frame];
  48. if (self) {
  49. self.contentView.backgroundColor = [UIColor clearColor];
  50. self.backgroundColor = [UIColor clearColor];
  51. [self.contentView addSubview:self.iconImg];
  52. [self.contentView addSubview:self.rightButton];
  53. self.height = SCREEN_WIDTH / 3.0 - 1;
  54. }
  55. return self;
  56. }
  57. #pragma mark 刷新cell
  58. - (void)resetCellWithImage:(PHAsset *)asset isSelected:(BOOL)iseSelected{
  59. WEAKSELF
  60. if (asset) {
  61. [self.imageManager requestImageForAsset:asset targetSize:CGSizeMake(SCREEN_WIDTH/2.0,SCREEN_WIDTH/2.0) contentMode:PHImageContentModeAspectFill options:self.opt resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
  62. weakSelf.iconImg.image = result;
  63. }];
  64. }
  65. self.rightButton.selected = iseSelected;
  66. self.rightButton.hidden = false;
  67. //刷新view
  68. self.iconImg.center = CGPointMake(self.width/2.0, self.height/2.0);
  69. [self.rightButton resetFrame:CGRectMake(0, 0, self.iconImg.width, self.iconImg.width) imageFrame:CGRectMake(self.width - W(30) , W(10), W(20), W(20))];
  70. }
  71. #pragma mark 点击事件
  72. - (void)btnClick:(UIButton *)sender{
  73. switch (sender.tag) {
  74. case 1:
  75. {
  76. if (self.blockClick) {
  77. self.blockClick(self);
  78. }
  79. }
  80. break;
  81. default:
  82. break;
  83. }
  84. }
  85. @end
  86. @implementation ImagePickerBottomView
  87. #pragma mark 懒加载
  88. -(UIButton *)btnComplete{
  89. if (_btnComplete == nil) {
  90. _btnComplete = [UIButton buttonWithType:UIButtonTypeCustom];
  91. _btnComplete.tag = 1;
  92. // [_btnComplete addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  93. _btnComplete.backgroundColor = [UIColor clearColor];
  94. [_btnComplete setTitleColor:COLOR_BLUE forState:UIControlStateNormal];
  95. _btnComplete.titleLabel.font = [UIFont systemFontOfSize:F(15)];
  96. [_btnComplete setTitle:@"完成" forState:(UIControlStateNormal)];
  97. _btnComplete.widthHeight = XY(W(100),W(49));
  98. }
  99. return _btnComplete;
  100. }
  101. -(UIButton *)btnSelectAlbum{
  102. if (_btnSelectAlbum == nil) {
  103. _btnSelectAlbum = [UIButton buttonWithType:UIButtonTypeCustom];
  104. _btnSelectAlbum.tag = 2;
  105. _btnSelectAlbum.backgroundColor = [UIColor clearColor];
  106. _btnSelectAlbum.titleLabel.font = [UIFont systemFontOfSize:F(15)];
  107. [_btnSelectAlbum setTitleColor:COLOR_LABEL forState:UIControlStateNormal];
  108. [_btnSelectAlbum setTitle:@"选择相册" forState:(UIControlStateNormal)];
  109. _btnSelectAlbum.widthHeight = XY(W(100),W(49));
  110. }
  111. return _btnSelectAlbum;
  112. }
  113. - (UIImageView *)iconArrow{
  114. if (_iconArrow == nil) {
  115. _iconArrow = [UIImageView new];
  116. // _iconArrow.image = [UIImage imageNamed:@"zzrs_qyzz"];
  117. _iconArrow.widthHeight = XY(W(15),W(15));
  118. }
  119. return _iconArrow;
  120. }
  121. #pragma mark 初始化
  122. - (instancetype)initWithFrame:(CGRect)frame{
  123. self = [super initWithFrame:frame];
  124. if (self) {
  125. [self addSubView];
  126. }
  127. return self;
  128. }
  129. //添加subview
  130. - (void)addSubView{
  131. self.widthHeight = XY(SCREEN_WIDTH, W(49));
  132. self.backgroundColor = [UIColor whiteColor];
  133. [self addSubview:self.btnComplete];
  134. [self addSubview:self.btnSelectAlbum];
  135. [self addSubview:self.iconArrow];
  136. }
  137. #pragma mark 创建
  138. + (instancetype)initWithModel:(id)model{
  139. ImagePickerBottomView * view = [ImagePickerBottomView new];
  140. [view resetViewWithModel:model];
  141. return view;
  142. }
  143. #pragma mark 刷新view
  144. - (void)resetViewWithModel:(id)model{
  145. [self removeSubViewWithTag:TAG_LINE];//移除线
  146. //刷新view
  147. self.btnComplete.rightTop = XY(SCREEN_WIDTH,0);
  148. self.btnSelectAlbum.leftTop = XY(0,0);
  149. }
  150. #pragma mark 点击事件
  151. - (void)btnClick:(UIButton *)sender{
  152. switch (sender.tag) {
  153. case 1:
  154. {
  155. }
  156. break;
  157. default:
  158. break;
  159. }
  160. }
  161. @end
  162. @interface ImagePikcerListBGVIew ()
  163. @end
  164. @implementation ImagePikcerListBGVIew
  165. #pragma mark 懒加载
  166. - (UIView *)listView{
  167. if (!_listView) {
  168. _listView = [UIView new];
  169. }
  170. return _listView;
  171. }
  172. - (UIControl *)viewBG{
  173. if (!_viewBG) {
  174. _viewBG = [UIControl new];
  175. _viewBG.backgroundColor = COLOR_BLACK_ALPHA_PER60;
  176. _viewBG.userInteractionEnabled = true;
  177. [_viewBG addTarget:self action:@selector(hideAnimation) forControlEvents:UIControlEventTouchUpInside];
  178. }
  179. return _viewBG;
  180. }
  181. - (NSArray *)aryDatas{
  182. if (!_aryDatas) {
  183. _aryDatas = [NSArray array];
  184. }
  185. return _aryDatas;
  186. }
  187. #pragma mark 初始化
  188. - (instancetype)initWithFrame:(CGRect)frame{
  189. self = [super initWithFrame:frame];
  190. if (self) {
  191. [self addSubView];
  192. }
  193. return self;
  194. }
  195. //添加subview
  196. - (void)addSubView{
  197. self.backgroundColor = [UIColor clearColor];
  198. self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
  199. self.alpha = 0;
  200. self.isAnimate = false;
  201. [self addSubview: self.viewBG];
  202. [self.viewBG addSubview:self.listView];
  203. [self addTarget:self action:@selector(hideAnimation) forControlEvents:UIControlEventTouchUpInside];
  204. }
  205. #pragma mark reset view
  206. - (void)resetViewWithAry:(NSArray *)arydatas height:(CGFloat)height{
  207. self.viewBG.frame = CGRectMake(0, 0, SCREEN_WIDTH, height);
  208. self.aryDatas = arydatas;
  209. [self resetViewList];
  210. self.listView.leftBottom = XY(0, self.viewBG.height);
  211. }
  212. - (void)resetViewList{
  213. [self.listView removeAllSubViews];
  214. CGFloat top = 0;
  215. for (int i = 0; i< self.aryDatas.count; i++) {
  216. PHAssetCollection *group = self.aryDatas[i];
  217. NSString *groupName = UnPackStr(group.localizedTitle);
  218. UIButton * btnTmp = [UIButton buttonWithType:UIButtonTypeCustom];
  219. btnTmp.tag = i+100;
  220. [btnTmp addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  221. btnTmp.backgroundColor = [UIColor whiteColor];
  222. btnTmp.titleLabel.font = [UIFont systemFontOfSize:F(15)];
  223. [btnTmp setTitleColor:COLOR_LABEL forState:UIControlStateNormal];
  224. [btnTmp setTitle:groupName forState:(UIControlStateNormal)];
  225. btnTmp.widthHeight = XY(W(100),W(49));
  226. btnTmp.leftTop = XY(0, top);
  227. [self.listView addSubview:btnTmp];
  228. top = btnTmp.bottom+1;
  229. }
  230. self.listView.widthHeight = XY(W(100), top);
  231. }
  232. #pragma mark 动画显示
  233. - (void)hideAnimation{
  234. if (!_isAnimate) {
  235. _isAnimate = true;
  236. WEAKSELF
  237. [UIView animateWithDuration:0.25 animations:^{
  238. self.alpha = 0;
  239. } completion:^(BOOL finished) {
  240. weakSelf.isAnimate = false;
  241. }];
  242. }
  243. }
  244. - (void)showAnimation{
  245. if (!_isAnimate) {
  246. _isAnimate = true;
  247. WEAKSELF
  248. [UIView animateWithDuration:0.25 animations:^{
  249. self.alpha = 1;
  250. } completion:^(BOOL finished) {
  251. weakSelf.isAnimate = false;
  252. }];
  253. }
  254. }
  255. #pragma mark 点击事件
  256. - (void)btnClick:(UIButton *)sender{
  257. NSInteger index = sender.tag - 100;
  258. PHAssetCollection *group = self.aryDatas[index];
  259. if (self.blockSelect) {
  260. self.blockSelect(group);
  261. }
  262. [self hideAnimation];
  263. }
  264. @end