KSImageShareViewController.m 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. //
  2. // KSImageShareViewController.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2022/9/21.
  6. //
  7. #import "KSImageShareViewController.h"
  8. #import "ChatAddressHeaderView.h"
  9. #import "JXCategoryView.h"
  10. #import "JXPagerListRefreshView.h"
  11. #import "ChatAddressBodyView.h"
  12. @interface KSImageShareViewController ()<JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate,JXCategoryViewDelegate>
  13. @property (nonatomic, strong) ChatAddressHeaderView *headView;
  14. @property (nonatomic, assign) NSInteger selectedIndex;
  15. @property (nonatomic, strong) NSMutableArray *listViewArray;
  16. @property (nonatomic, copy) ShareGroupCallback callback;
  17. @end
  18. @implementation KSImageShareViewController
  19. - (void)backAction {
  20. if (self.callback) {
  21. self.callback(NO, @"已取消");
  22. }
  23. [self.navigationController popViewControllerAnimated:YES];
  24. }
  25. - (void)shareGroupCallback:(ShareGroupCallback)callback {
  26. if (callback) {
  27. self.callback = callback;
  28. }
  29. }
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. // Do any additional setup after loading the view.
  33. _titles = @[@"班级",@"老师"];
  34. [self allocTitle:@"分享"];
  35. [self configUI];
  36. }
  37. - (void)configUI {
  38. [self.scrollView removeFromSuperview];
  39. self.view.backgroundColor = HexRGB(0xf6f8f9);
  40. [self.view addSubview:self.headView];
  41. self.headView.frame = CGRectMake(0, 0, KPortraitWidth, 60);
  42. MJWeakSelf;
  43. [self.headView chatAddressbookAction:^(CHATADDRESSTYPE type, NSString * _Nullable searchKey) {
  44. [weakSelf topViewAction:type search:searchKey];
  45. }];
  46. _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 60, KPortraitWidth, 10)];
  47. _categoryView.backgroundColor = HexRGB(0xf6f8f9);
  48. self.categoryView.titles = self.titles;
  49. self.categoryView.delegate = self;
  50. self.categoryView.titleFont = [UIFont systemFontOfSize:16.0f];
  51. self.categoryView.titleSelectedFont = [UIFont systemFontOfSize:16.0f weight:UIFontWeightMedium];
  52. self.categoryView.titleSelectedColor = THEMECOLOR;
  53. self.categoryView.titleColor = HexRGB(0x777777);
  54. self.categoryView.titleColorGradientEnabled = YES;
  55. self.categoryView.hidden = YES;
  56. _pagerView = [self preferredPagingView];
  57. self.pagerView.frame = CGRectMake(0, 60, KPortraitWidth, KPortraitHeight - kNaviBarHeight-60 - kTabBarHeight);
  58. self.pagerView.listContainerView.categoryNestPagingEnabled = YES;
  59. self.pagerView.mainTableView.gestureDelegate = self;
  60. self.pagerView.backgroundColor = [UIColor clearColor];
  61. self.pagerView.mainTableView.backgroundColor = [UIColor clearColor];
  62. [self.view addSubview:self.pagerView];
  63. self.categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
  64. }
  65. - (void)topViewAction:(CHATADDRESSTYPE)type search:(NSString *)searchKey {
  66. switch (type) {
  67. case CHATADDRESSTYPE_PERSON: // 联系人
  68. {
  69. [self.categoryView selectItemAtIndex:1];
  70. self.selectedIndex = 1;
  71. }
  72. break;
  73. case CHATADDRESSTYPE_GROUP: // 群组
  74. {
  75. [self.categoryView selectItemAtIndex:0];
  76. self.selectedIndex = 0;
  77. }
  78. break;
  79. case CHATADDRESSTYPE_SEARCH: // 搜索
  80. {
  81. [self searchRequest:searchKey];
  82. }
  83. break;
  84. default:
  85. break;
  86. }
  87. }
  88. - (void)searchRequest:(NSString *)searchKey {
  89. if (self.listViewArray.count > self.selectedIndex) {
  90. ChatAddressBodyView *listView = self.listViewArray[self.selectedIndex];
  91. listView.searchKey = searchKey;
  92. [listView refreshAndRequestData];
  93. }
  94. }
  95. - (void)viewWillAppear:(BOOL)animated {
  96. [super viewWillAppear:animated];
  97. self.navigationController.interactivePopGestureRecognizer.enabled = YES;
  98. if (self.listViewArray.count > self.categoryView.selectedIndex) {
  99. id value = self.listViewArray[self.categoryView.selectedIndex];
  100. if ([value isKindOfClass:[KSJXBodyView class]]) {
  101. KSJXBodyView *listView = (KSJXBodyView *)value;
  102. [listView beginFirstRefresh];
  103. }
  104. }
  105. }
  106. - (void)viewDidAppear:(BOOL)animated {
  107. [super viewDidAppear:animated];
  108. self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
  109. }
  110. - (JXPagerView *)preferredPagingView {
  111. return [[JXPagerListRefreshView alloc] initWithDelegate:self];
  112. }
  113. #pragma mark - JXPagerViewDelegate
  114. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  115. return [UIView new];
  116. }
  117. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  118. return CGFLOAT_MIN;
  119. }
  120. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  121. return 10;
  122. }
  123. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  124. return self.categoryView;
  125. }
  126. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  127. //和categoryView的item数量一致
  128. return self.titles.count;
  129. }
  130. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
  131. ChatAddressBodyView *listView = [[ChatAddressBodyView alloc] init];
  132. listView.naviController = self.navigationController;
  133. listView.isShareImage = YES;
  134. listView.shareImage = self.shareImage;
  135. listView.filePath = [self getImagePth];
  136. MJWeakSelf;
  137. [listView shareCallback:^(BOOL isSuccess, NSString * _Nonnull desc) {
  138. if (weakSelf.callback) {
  139. [weakSelf.navigationController popViewControllerAnimated:YES];
  140. weakSelf.callback(isSuccess, desc);
  141. }
  142. }];
  143. [self.listViewArray addObject:listView];
  144. if (index == 0) {
  145. listView.selectIndex = 0;
  146. }else if (index == 1) {
  147. listView.selectIndex = 1;
  148. }
  149. [listView beginFirstRefresh];
  150. return listView;
  151. }
  152. #pragma mark - JXCategoryViewDelegate
  153. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  154. BOOL scrollPersonTable = index == 0;
  155. [self.headView scrollPersonTable:scrollPersonTable];
  156. self.selectedIndex = index;
  157. }
  158. #pragma mark - JXPagerMainTableViewGestureDelegate
  159. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  160. //禁止categoryView左右滑动的时候,上下和左右都可以滚动
  161. if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
  162. return NO;
  163. }
  164. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  165. }
  166. - (NSMutableArray *)listViewArray {
  167. if (!_listViewArray) {
  168. _listViewArray = [NSMutableArray array];
  169. }
  170. return _listViewArray;
  171. }
  172. #pragma mark - JXCategoryListContentViewDelegate
  173. - (UIView *)listView {
  174. return self.view;
  175. }
  176. - (ChatAddressHeaderView *)headView {
  177. if (!_headView) {
  178. _headView = [ChatAddressHeaderView shareInstance];
  179. }
  180. return _headView;
  181. }
  182. - (void)setSelectedIndex:(NSInteger)selectedIndex {
  183. _selectedIndex = selectedIndex;
  184. ChatAddressBodyView *listView = self.listViewArray[selectedIndex];
  185. NSString *searchKey = listView.searchKey;
  186. self.headView.searchField.text = searchKey;
  187. }
  188. - (void)setShareImage:(UIImage *)shareImage {
  189. _shareImage = shareImage;
  190. [self saveImage];
  191. }
  192. - (void)saveImage {
  193. UIImage * imgsave = self.shareImage;
  194. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
  195. NSString *path = [[paths objectAtIndex:0]stringByAppendingPathComponent:
  196. [NSString stringWithFormat:@"shareImage.png"]];
  197. [UIImagePNGRepresentation(imgsave) writeToFile:path atomically:YES];
  198. }
  199. - (NSString *)getImagePth {
  200. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
  201. NSString *filePath = [[paths objectAtIndex:0]stringByAppendingPathComponent:
  202. [NSString stringWithFormat:@"shareImage.png"]];
  203. return filePath;
  204. }
  205. /*
  206. #pragma mark - Navigation
  207. // In a storyboard-based application, you will often want to do a little preparation before navigation
  208. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  209. // Get the new view controller using [segue destinationViewController].
  210. // Pass the selected object to the new view controller.
  211. }
  212. */
  213. @end