JXSelectImageView.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. //
  2. // JXSelectImageView.m
  3. //
  4. // Created by Reese on 13-8-22.
  5. // Copyright (c) 2013年 Reese. All rights reserved.
  6. //
  7. #import "JXSelectImageView.h"
  8. #define SELECTIMAGE_WIDTH 40 // 图片宽度
  9. //动态间距
  10. #define DWIDTH (JX_SCREEN_WIDTH - 200)/5.0
  11. //动态间距
  12. #define DHEIGHT (218 - 110)/3.0
  13. @implementation JXSelectImageView
  14. @synthesize delegate;
  15. - (id)initWithFrame:(CGRect)frame
  16. {
  17. self = [super initWithFrame:frame];
  18. if (self) {
  19. [self setBackgroundColor:HEXCOLOR(0xF9F9F9)];
  20. self.scrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
  21. self.scrollView.delegate = self;
  22. self.scrollView.showsVerticalScrollIndicator = NO;
  23. self.scrollView.showsHorizontalScrollIndicator = NO;
  24. [self addSubview:self.scrollView]; self.scrollView.backgroundColor=[UIColor whiteColor];
  25. self.helperScrollV = [[UIScrollView alloc] initWithFrame:self.bounds];
  26. self.helperScrollV.delegate = self;
  27. self.helperScrollV.showsVerticalScrollIndicator = NO;
  28. self.helperScrollV.showsHorizontalScrollIndicator = NO;
  29. self.helperScrollV.hidden = YES;
  30. [self addSubview:self.helperScrollV]; self.helperScrollV.backgroundColor=[UIColor whiteColor];
  31. UIView* line = [[UIView alloc]initWithFrame:CGRectMake(0,0,JX_SCREEN_WIDTH * 2,8)];
  32. line.backgroundColor =[UIColor whiteColor]; THE_LINE_COLOR;
  33. [self.scrollView addSubview:line];
  34. // 创建功能栏
  35. int h = SELECTIMAGE_WIDTH+15+9;
  36. int inset = (JX_SCREEN_WIDTH-SELECTIMAGE_WIDTH*4)/5;
  37. int margeY = (frame.size.height - (THE_DEVICE_HAVE_HEAD ? 75 : 40) - (h * 2)) / 2;
  38. int n = 0;
  39. int m = 1;
  40. int X = inset;
  41. int Y = margeY;
  42. UIView *button;
  43. // 照片
  44. button = [self createButtonWithImage:@"im_photo_button_normal" highlight:@"im_photo_button_press" target:delegate selector:self.onImage title:Localized(@"JX_Photo")];
  45. button.frame = CGRectMake(X, Y, SELECTIMAGE_WIDTH, h);
  46. // 拍摄
  47. n = (n + 1) >= 4 ? 0 : n + 1;
  48. m += 1;
  49. X = m >8 ? SELECTIMAGE_WIDTH *n + (n+1)*inset+JX_SCREEN_WIDTH : SELECTIMAGE_WIDTH *n + (n+1)*inset;
  50. Y = m > 4 && m <=8 ? h+margeY*2 : margeY;
  51. button = [self createButtonWithImage:@"im_pickup_button_normal" highlight:@"im_pickup_button_press" target:delegate selector:self.onCamera title:Localized(@"JX_PhotoAndVideo")];
  52. button.frame = CGRectMake(X, Y, SELECTIMAGE_WIDTH, h);
  53. // // 收藏
  54. // n = (n + 1) >= 4 ? 0 : n + 1;
  55. // m += 1;
  56. // X = m >8 ? SELECTIMAGE_WIDTH *n + (n+1)*inset+JX_SCREEN_WIDTH : SELECTIMAGE_WIDTH *n + (n+1)*inset;
  57. // Y = m > 4 && m <=8 ? h+margeY*2 : margeY;
  58. // button = [self createButtonWithImage:@"im_collection_button_normal" highlight:@"im_collection_button_press" target:delegate selector:self.onCollection title:Localized(@"JX_Collection")];
  59. // button.frame = CGRectMake(X, Y, SELECTIMAGE_WIDTH, h);
  60. // 位置
  61. // if ([g_config.isOpenPositionService intValue] == 0) {
  62. // n = (n + 1) >= 4 ? 0 : n + 1;
  63. // m += 1;
  64. // X = m >8 ? SELECTIMAGE_WIDTH *n + (n+1)*inset+JX_SCREEN_WIDTH : SELECTIMAGE_WIDTH *n + (n+1)*inset;
  65. // Y = m > 4 && m <=8 ? h+margeY*2 : margeY;
  66. // button = [self createButtonWithImage:@"im_map_button_normal" highlight:@"im_map_button_press" target:delegate selector:self.onLocation title:Localized(@"JX_Location")];
  67. // button.frame = CGRectMake(X, Y, SELECTIMAGE_WIDTH, h);
  68. // }
  69. // enablePayModule
  70. if ([g_config.enablePayModule boolValue] && !self.isGroupMessages && !self.isDevice) {
  71. if ([g_App.isShowRedPacket boolValue]) {
  72. // 发红包
  73. n = (n + 1) >= 4 ? 0 : n + 1;
  74. m += 1;
  75. X = m >8 ? SELECTIMAGE_WIDTH *n + (n+1)*inset+JX_SCREEN_WIDTH : SELECTIMAGE_WIDTH *n + (n+1)*inset;
  76. Y = m > 4 && m <=8 ? h+margeY*2 : margeY;
  77. button = [self createButtonWithImage:@"im_awarda_a_bonus_normal" highlight:@"im_awarda_a_bonus_press" target:delegate selector:self.onGift title:Localized(@"JX_SendGift")];
  78. button.frame = CGRectMake(X, Y, SELECTIMAGE_WIDTH, h);
  79. }
  80. // if (!self.isGroup) {
  81. // 转账
  82. // n = (n + 1) >= 4 ? 0 : n + 1;
  83. // m += 1;
  84. // X = m >8 ? SELECTIMAGE_WIDTH *n + (n+1)*inset+JX_SCREEN_WIDTH : SELECTIMAGE_WIDTH *n + (n+1)*inset;
  85. // Y = m > 4 && m <=8 ? h+margeY*2 : margeY;
  86. // button = [self createButtonWithImage:@"im_tool_transfer_button_normal" highlight:@"im_tool_transfer_button_press" target:delegate selector:self.onTransfer title:Localized(@"JX_Transfer")];
  87. // button.frame = CGRectMake(X, Y, SELECTIMAGE_WIDTH, h);
  88. // }
  89. }
  90. #if TAR_IM
  91. #ifdef Meeting_Version
  92. if (!self.isGroupMessages && !self.isDevice) {
  93. // 语音通话 or 视频会议
  94. NSString *str;
  95. if (_isGroup) {
  96. str = @"视频通话";// Localized(@"JXSettingVC_VideoMeeting");
  97. }else {
  98. n = (n + 1) >= 4 ? 0 : n + 1;
  99. m += 1;
  100. X = m >8 ? SELECTIMAGE_WIDTH *n + (n+1)*inset+JX_SCREEN_WIDTH : SELECTIMAGE_WIDTH *n + (n+1)*inset;
  101. Y = m > 4 && m <=8 ? h+margeY*2 : margeY;
  102. str = Localized(@"JX_VideoChat");
  103. button = [self createButtonWithImage:@"im_audio_button_normal" highlight:@"im_audio_button_press" target:delegate selector:self.onAudioChat title:str];
  104. button.frame = CGRectMake(X, Y, SELECTIMAGE_WIDTH, h);
  105. }
  106. }
  107. #endif
  108. #endif
  109. // 名片
  110. // if (!_isGroup) {
  111. // n = (n + 1) >= 4 ? 0 : n + 1;
  112. // m += 1;
  113. // X = m >8 ? SELECTIMAGE_WIDTH *n + (n+1)*inset+JX_SCREEN_WIDTH : SELECTIMAGE_WIDTH *n + (n+1)*inset;
  114. // Y = m > 4 && m <=8 ? h+margeY*2 : margeY;
  115. // button = [self createButtonWithImage:@"im_card_button_normal" highlight:@"im_card_button_press" target:delegate selector:self.onCard title:Localized(@"JX_Card")];
  116. // button.frame = CGRectMake(X, Y, SELECTIMAGE_WIDTH, h);
  117. // }
  118. if (self.isGroup) {
  119. //Localized(@"JX_Shake")
  120. // 戳一戳
  121. if ([_data.role intValue]==1||[_data.role intValue]==2) {
  122. n = (n + 1) >= 4 ? 0 : n + 1;
  123. m += 1;
  124. X = m >8 ? SELECTIMAGE_WIDTH *n + (n+1)*inset+JX_SCREEN_WIDTH : SELECTIMAGE_WIDTH *n + (n+1)*inset;
  125. Y = m > 4 && m <=8 ? h+margeY*2 : margeY;
  126. button = [self createButtonWithImage:@"im_tool_shake_normal" highlight:@"im_tool_shake_press" target:delegate selector:self.onShake title:@"抖TA"];
  127. button.frame = CGRectMake(X, Y, SELECTIMAGE_WIDTH, h);
  128. }
  129. }else{
  130. // 戳一戳
  131. n = (n + 1) >= 4 ? 0 : n + 1;
  132. m += 1;
  133. X = m >8 ? SELECTIMAGE_WIDTH *n + (n+1)*inset+JX_SCREEN_WIDTH : SELECTIMAGE_WIDTH *n + (n+1)*inset;
  134. Y = m > 4 && m <=8 ? h+margeY*2 : margeY;
  135. button = [self createButtonWithImage:@"im_tool_shake_normal" highlight:@"im_tool_shake_press" target:delegate selector:self.onShake title:@"抖TA"];
  136. //Localized(@"JX_Shake")
  137. button.frame = CGRectMake(X, Y, SELECTIMAGE_WIDTH, h);
  138. }
  139. // // 文件
  140. // n = (n + 1) >= 4 ? 0 : n + 1;
  141. // m += 1;
  142. // X = m >8 ? SELECTIMAGE_WIDTH *n + (n+1)*inset+JX_SCREEN_WIDTH : SELECTIMAGE_WIDTH *n + (n+1)*inset;
  143. // Y = m > 4 && m <=8 ? h+margeY*2 : margeY;
  144. // button = [self createButtonWithImage:@"im_file_button_normal" highlight:@"im_file_button_press" target:delegate selector:self.onFile title:Localized(@"JX_File")];
  145. // button.frame = CGRectMake(X, Y, SELECTIMAGE_WIDTH, h);
  146. //
  147. // // 联系人
  148. // n = (n + 1) >= 4 ? 0 : n + 1;
  149. // m += 1;
  150. // X = m >8 ? SELECTIMAGE_WIDTH *n + (n+1)*inset+JX_SCREEN_WIDTH : SELECTIMAGE_WIDTH *n + (n+1)*inset;
  151. // Y = m > 4 && m <=8 ? h+margeY*2 : margeY;
  152. // button = [self createButtonWithImage:@"im_ab_button_normal" highlight:@"im_ab_button_press" target:delegate selector:self.onAddressBook title:Localized(@"JX_SelectImageContact")];
  153. // button.frame = CGRectMake(X, Y, SELECTIMAGE_WIDTH, h);
  154. //
  155. // // 群助手
  156. // if (self.isGroup) {
  157. // n = (n + 1) >= 4 ? 0 : n + 1;
  158. // m += 1;
  159. // X = m >8 ? SELECTIMAGE_WIDTH *n + (n+1)*inset+JX_SCREEN_WIDTH : SELECTIMAGE_WIDTH *n + (n+1)*inset;
  160. // Y = m > 4 && m <=8 ? h+margeY*2 : margeY;
  161. // button = [self createButtonWithImage:@"im_group_button_normal" highlight:@"im_group_button_press" target:delegate selector:self.onGroupHelper title:Localized(@"JX_GroupAssistants")];
  162. // button.frame = CGRectMake(X, Y, SELECTIMAGE_WIDTH, h);
  163. // }
  164. if (m > 8) {
  165. self.scrollView.contentSize = CGSizeMake(JX_SCREEN_WIDTH * 2, 0);
  166. self.scrollView.pagingEnabled = YES;
  167. _pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(100, self.frame.size.height-(THE_DEVICE_HAVE_HEAD ? 65 : 30), JX_SCREEN_WIDTH-200, 30)];
  168. _pageControl.numberOfPages = 2;
  169. _pageControl.pageIndicatorTintColor = [UIColor grayColor];
  170. _pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
  171. [_pageControl addTarget:self action:@selector(actionPage) forControlEvents:UIControlEventTouchUpInside];
  172. [self addSubview:_pageControl];
  173. }
  174. }
  175. return self;
  176. }
  177. - (void)actionPage {
  178. }
  179. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  180. int index = scrollView.contentOffset.x/320;
  181. int mod = fmod(scrollView.contentOffset.x,320);
  182. if( mod >= 160)
  183. index++;
  184. _pageControl.currentPage = index;
  185. }
  186. -(void)dealloc
  187. {
  188. // [super dealloc];
  189. }
  190. - (void)setHelpers:(NSArray *)helpers {
  191. for (UIView *subView in self.helperScrollV.subviews) {
  192. [subView removeFromSuperview];
  193. }
  194. if (!self.isWin && helpers.count <= 0) {
  195. UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake((JX_SCREEN_WIDTH-60)/2, 44+20, 60, 60)];
  196. img.image = [UIImage imageNamed:@"group_helper_notData"];
  197. [self.helperScrollV addSubview:img];
  198. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(img.frame)+10, JX_SCREEN_WIDTH, 20)];
  199. label.font = SYSFONT(15);
  200. label.text = Localized(@"JX_GroupNotAssistants");
  201. label.textAlignment = NSTextAlignmentCenter;
  202. label.textColor = HEXCOLOR(0x6E7377);
  203. [self.helperScrollV addSubview:label];
  204. return;
  205. }
  206. // 创建群助手
  207. CGFloat width = JX_SCREEN_WIDTH/2;
  208. int height = (self.frame.size.height-30-44)/3;
  209. UIView *lastView = nil;
  210. int m = 0;
  211. int count = self.isWin ? (int)(helpers.count + 1) : (int)helpers.count;
  212. for (int i = 0; i < count; i++) {
  213. JXGroupHeplerModel *model;
  214. if (i < helpers.count) {
  215. model = helpers[i];
  216. }
  217. UIView *view;
  218. if (lastView == nil) {
  219. view = [self createButtonWithFrame:CGRectMake(0, 0, width, height) iconUrl:model.helperModel.iconUrl title:model.helperModel.name index:i];
  220. }else {
  221. CGFloat maxX = CGRectGetMaxX(lastView.frame);
  222. int ii = ((int)maxX%(int)JX_SCREEN_WIDTH);
  223. if (ii <= 0) {
  224. int x = (int)((int)(CGRectGetMaxX(lastView.frame)+1)/(int)JX_SCREEN_WIDTH);
  225. if (CGRectGetMaxY(lastView.frame)+height > height*3) {
  226. view = [self createButtonWithFrame:CGRectMake(x*JX_SCREEN_WIDTH, 0, width, height) iconUrl:model.helperModel.iconUrl title:model.helperModel.name index:i];
  227. }else {
  228. view = [self createButtonWithFrame:CGRectMake((x-1)*JX_SCREEN_WIDTH, CGRectGetMaxY(lastView.frame), width, height) iconUrl:model.helperModel.iconUrl title:model.helperModel.name index:i];
  229. }
  230. }else {
  231. view = [self createButtonWithFrame:CGRectMake(CGRectGetMaxX(lastView.frame), CGRectGetMinY(lastView.frame), width, height) iconUrl:model.helperModel.iconUrl title:model.helperModel.name index:i];
  232. }
  233. }
  234. lastView = view;
  235. m += 1;
  236. }
  237. if (m > 6) {
  238. int num = m%6 > 0 ? m/6+1 : m/6;
  239. self.helperScrollV.contentSize = CGSizeMake(JX_SCREEN_WIDTH * num, 0);
  240. self.helperScrollV.pagingEnabled = YES;
  241. _pageControl.numberOfPages = num;
  242. }else {
  243. self.pageControl.hidden = YES;
  244. }
  245. }
  246. - (void)resetPageControl {
  247. _pageControl.numberOfPages = 2;
  248. }
  249. - (void)didView:(UITapGestureRecognizer *)tap {
  250. UIView *view = tap.view;
  251. self.viewIndex = view.tag;
  252. self.isDidSet = NO;
  253. [self.delegate performSelectorOnMainThread:self.onDidView withObject:self waitUntilDone:NO];
  254. }
  255. - (void)didSetImgV:(UITapGestureRecognizer *)tap {
  256. UIView *view = tap.view;
  257. self.viewIndex = view.tag;
  258. self.isDidSet = YES;
  259. [self.delegate performSelectorOnMainThread:self.onDidView withObject:self waitUntilDone:NO];
  260. }
  261. - (UIView *)createButtonWithImage:(NSString *)normalImage
  262. highlight:(NSString *)clickIamge
  263. target:(id)target
  264. selector:(SEL)selector
  265. title:(NSString*)title
  266. {
  267. UIView* v = [[UIView alloc]init];
  268. UIButton* btn = [UIFactory createButtonWithImage:normalImage highlight:clickIamge target:target selector:selector];
  269. btn.frame = CGRectMake(0, 0, SELECTIMAGE_WIDTH, SELECTIMAGE_WIDTH);
  270. [v addSubview:btn];
  271. UILabel* p = [[UILabel alloc]initWithFrame:CGRectMake(-15, SELECTIMAGE_WIDTH+9, SELECTIMAGE_WIDTH+30, 15)];
  272. p.text = title;
  273. p.font = g_factory.font13;
  274. p.textAlignment = NSTextAlignmentCenter;
  275. p.textColor = HEXCOLOR(0x666666);
  276. [v addSubview:p];
  277. [self.scrollView addSubview:v];
  278. return v;
  279. }
  280. - (UIView *)createButtonWithFrame:(CGRect)frame iconUrl:(NSString *)iconUrl title:(NSString *)title index:(NSInteger)index {
  281. UIView* view = [[UIView alloc]initWithFrame:frame];
  282. view.tag = index;
  283. UIView *riLine = [[UIView alloc] initWithFrame:CGRectMake(frame.size.width-LINE_WH, 0, LINE_WH, frame.size.height)];
  284. riLine.backgroundColor = THE_LINE_COLOR;
  285. [view addSubview:riLine];
  286. UIView *botLine = [[UIView alloc] initWithFrame:CGRectMake(0, frame.size.height-LINE_WH, frame.size.width, LINE_WH)];
  287. botLine.backgroundColor = THE_LINE_COLOR;
  288. [view addSubview:botLine];
  289. if (index == 0 || index == 1) {
  290. UIView* topLine = [[UIView alloc]initWithFrame:CGRectMake(0,0,frame.size.width,LINE_WH)];
  291. topLine.backgroundColor = THE_LINE_COLOR;
  292. [view addSubview:topLine];
  293. }
  294. if (iconUrl.length <= 0 && title.length <= 0) {
  295. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake((frame.size.width-20)/2, (frame.size.height-20)/2, 20, 20)];
  296. [btn setImage:[UIImage imageNamed:@"groupHelper_add"] forState:UIControlStateNormal];
  297. [btn addTarget:self.delegate action:self.onGroupHelperList forControlEvents:UIControlEventTouchUpInside];
  298. [view addSubview:btn];
  299. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self.delegate action:self.onGroupHelperList];
  300. [view addGestureRecognizer:tap];
  301. }else {
  302. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didView:)];
  303. [view addGestureRecognizer:tap];
  304. UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(10, (frame.size.height-30)/2, 30, 30)];
  305. imgV.layer.masksToBounds = YES;
  306. imgV.layer.cornerRadius = imgV.frame.size.width/2;
  307. [view addSubview:imgV];
  308. [imgV sd_setImageWithURL:[NSURL URLWithString:iconUrl] placeholderImage:[UIImage imageNamed:@"avatar_normal"]];
  309. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(imgV.frame)+10, (frame.size.height-18)/2, frame.size.width- 90, 16)];
  310. label.text = title;
  311. label.textColor = HEXCOLOR(0x6E7377);
  312. label.font = SYSFONT(14);
  313. [view addSubview:label];
  314. if (self.isWin) {
  315. UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(frame.size.width-40, 0, 40, frame.size.height)];
  316. [view addSubview:view1];
  317. UIImageView *setImgV = [[UIImageView alloc] initWithFrame:CGRectMake(10, (view1.frame.size.height-20)/2, 20, 20)];
  318. setImgV.image = [UIImage imageNamed:@"groupHelper_set"];
  319. setImgV.userInteractionEnabled = YES;
  320. setImgV.tag = index;
  321. [view1 addSubview:setImgV];
  322. UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didSetImgV:)];
  323. [setImgV addGestureRecognizer:tap1];
  324. }
  325. }
  326. [self.helperScrollV addSubview:view];
  327. return view;
  328. }
  329. @end