CustomReceiptHomeViewController.m 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // CustomReceiptHomeViewController.m
  2. // IOBSS 2.0
  3. //
  4. // Created by 刘瀚璘 on 2017.7.14
  5. // Copyright 2017 沈阳东科云信软件有限公司. All rights reserved.
  6. //
  7. // 系统名称:
  8. // 功能描述:定制品回执页面
  9. #import "CustomReceiptHomeViewController.h"
  10. @interface CustomReceiptHomeViewController (){
  11. /**
  12. 判断是否加载过已回执界面
  13. */
  14. bool isLoad;
  15. }
  16. @end
  17. @implementation CustomReceiptHomeViewController
  18. /**
  19. 滑动的个数
  20. */
  21. static int _count = 2;
  22. #pragma mark - 公共函数
  23. /**
  24. 公共函数
  25. */
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. [self initUI];
  29. }
  30. /**
  31. 安全区视图发生变化
  32. */
  33. -(void)viewSafeAreaInsetsDidChange{
  34. self.view.backgroundColor = [UIColor whiteColor];
  35. _mainScrollView.frame = CGRectMake(0, 40, Screen_Width,self.view.safeAreaLayoutGuide.layoutFrame.size.height-40);
  36. for (NSInteger i = 0; i < _mainScrollView.subviews.count; i++) {
  37. _mainScrollView.subviews[i].frame = CGRectMake(Screen_Width * i, 0, Screen_Width,CGRectGetHeight(_mainScrollView.frame));
  38. }
  39. [self.noReceiptVC viewSafeAreaInsetsDidChange];
  40. [self.receiptVC viewSafeAreaInsetsDidChange];
  41. [super viewSafeAreaInsetsDidChange];
  42. }
  43. /**
  44. 滑动label位置
  45. @param scrollView
  46. */
  47. - (void)scrollViewDidScroll:(UIScrollView *) scrollView {
  48. //实时计算当前位置,实现和titleView上的按钮的联动
  49. CGFloat contentOffSetX = scrollView.contentOffset.x;
  50. CGFloat X = contentOffSetX/_count;
  51. CGRect frame = _sliderLabel.frame;
  52. frame.origin.x = X;
  53. _sliderLabel.frame = frame;
  54. }
  55. /**
  56. 滑动完成
  57. @param scrollView <#scrollView description#>
  58. */
  59. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
  60. CGFloat contentOffSetX = scrollView.contentOffset.x;
  61. int index_ = contentOffSetX/Screen_Width;
  62. [self sliderWithTag:index_+1];
  63. }
  64. #pragma mark - 事件
  65. /**
  66. 点击已回执,未回执切换
  67. @param btn
  68. */
  69. - (void)sliderAction:(UIButton *) btn{
  70. if (self.currentIndex == btn.tag) {
  71. return;
  72. }
  73. if(btn.tag == 2){
  74. if(!isLoad){
  75. [_receiptVC loadDataView];
  76. isLoad = true;
  77. }
  78. }
  79. [self.view endEditing:YES];
  80. [self sliderAnimationWithTag:btn.tag];
  81. [UIView animateWithDuration:0.3 animations:^{
  82. _mainScrollView.contentOffset = CGPointMake(Screen_Width*(btn.tag-1), 0);
  83. } completion:^(BOOL finished) {
  84. }];
  85. }
  86. /**
  87. 滑动tag
  88. @param tag
  89. */
  90. - (void)sliderAnimationWithTag:(NSInteger) tag {
  91. self.currentIndex = tag;
  92. _receiptBtn.selected = NO;
  93. _noReceiptBtn.selected = NO;
  94. UIButton *sender = [self buttonWithTag:tag];
  95. sender.selected = YES;
  96. //动画
  97. [UIView animateWithDuration:0.3 animations:^{
  98. _sliderLabel.frame = CGRectMake(sender.frame.origin.x, _sliderLabel.frame.origin.y, _sliderLabel.frame.size.width, _sliderLabel.frame.size.height);
  99. } completion:^(BOOL finished) {
  100. }];
  101. }
  102. /**
  103. 滑动tag
  104. @param tag
  105. */
  106. - (void)sliderWithTag:(NSInteger) tag {
  107. self.currentIndex = tag;
  108. _noReceiptBtn.selected = NO;
  109. _receiptBtn.selected = NO;
  110. if(tag == 2){
  111. if(!isLoad){
  112. [_receiptVC loadDataView];
  113. isLoad = true;
  114. }
  115. }
  116. UIButton *sender = [self buttonWithTag:tag];
  117. sender.selected = YES;
  118. //动画
  119. _sliderLabel.frame = CGRectMake(sender.frame.origin.x, _sliderLabel.frame.origin.y, _sliderLabel.frame.size.width, _sliderLabel.frame.size.height);
  120. }
  121. /*
  122. 获得导航按钮
  123. */
  124. - (UIButton *)buttonWithTag:(NSInteger ) tag {
  125. if (tag == 1) {
  126. return _noReceiptBtn;
  127. }
  128. else if (tag == 2){
  129. return _receiptBtn;
  130. }
  131. else{
  132. return nil;
  133. }
  134. }
  135. #pragma mark - 初始化
  136. /**
  137. 未回执实例
  138. @return 实例
  139. */
  140. - ( CustomNoReceiptViewController *) noReceiptVC {
  141. if (_noReceiptVC == nil) {
  142. _noReceiptVC = [[CustomNoReceiptViewController alloc] init];
  143. _noReceiptVC.navigation=self.navigationController;
  144. }
  145. return _noReceiptVC;
  146. }
  147. /**
  148. 已回执实例
  149. @return 实例
  150. */
  151. - (CustomReceiptViewController *) receiptVC {
  152. if (_receiptVC == nil) {
  153. _receiptVC = [[CustomReceiptViewController alloc] init];
  154. _receiptVC.navigation=self.navigationController; }
  155. return _receiptVC;
  156. }
  157. /**
  158. 初始化布局
  159. */
  160. - (void)initUI{
  161. self.navigationItem.title = @"定制品回执一览";
  162. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  163. [button setImage:[UIImage imageNamed:@"icon_back.png"] forState:UIControlStateNormal];
  164. [button addTarget:self action:@selector(goBack)
  165. forControlEvents:UIControlEventTouchUpInside];
  166. button.frame = CGRectMake(0, 0,45,22);
  167. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  168. self.navigationItem.leftBarButtonItem = menuButton;
  169. UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 40)];
  170. [self.view addSubview:navView];
  171. [self.view setBackgroundColor:[UIColor whiteColor]];
  172. _noReceiptBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  173. [_noReceiptBtn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
  174. [_noReceiptBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  175. _noReceiptBtn.frame = CGRectMake(0, 0, Screen_Width/_count, navView.frame.size.height);
  176. _noReceiptBtn.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  177. [_noReceiptBtn addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside];
  178. [_noReceiptBtn setTitle:@"未回执" forState:UIControlStateNormal];
  179. _noReceiptBtn.tag = 1;
  180. _noReceiptBtn.selected = YES;
  181. [navView addSubview:_noReceiptBtn];
  182. _receiptBtn= [UIButton buttonWithType:UIButtonTypeCustom];
  183. _receiptBtn.frame = CGRectMake(CGRectGetMaxX(_noReceiptBtn.frame),0, Screen_Width/_count, navView.frame.size.height);
  184. [_receiptBtn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
  185. [_receiptBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  186. _receiptBtn.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  187. [_receiptBtn addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside];
  188. [_receiptBtn setTitle:@"已回执" forState:UIControlStateNormal];
  189. _receiptBtn.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
  190. _receiptBtn.tag = 2;
  191. [navView addSubview: _receiptBtn];
  192. _sliderLabel = [[UILabel alloc]initWithFrame:CGRectMake(_noReceiptBtn.frame.origin.x, 40-2, Screen_Width/_count, 2)];
  193. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(((Screen_Width/_count)-50)/2, 0, 50, 2)];
  194. line.backgroundColor = [UIColor redColor];
  195. [_sliderLabel addSubview:line];
  196. [navView addSubview:_sliderLabel];
  197. [self initSrollView];
  198. [self sliderWithTag:self.currentIndex+1];
  199. }
  200. /**
  201. 初始化srollView
  202. */
  203. - (void)initSrollView {
  204. _mainScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 40, Screen_Width, self.view.frame.size.height)];
  205. _mainScrollView.delegate = self;
  206. _mainScrollView.backgroundColor = [UIColor whiteColor];
  207. _mainScrollView.pagingEnabled = YES;
  208. _mainScrollView.showsHorizontalScrollIndicator = NO;
  209. _mainScrollView.showsVerticalScrollIndicator = NO;
  210. [self.view addSubview:_mainScrollView];
  211. NSArray *views = @[self.noReceiptVC.view,self.receiptVC.view];
  212. for (NSInteger i = 0; i< views.count; i++) {
  213. //把三个vc的view依次贴到mainScrollView上面
  214. UIView *pageView = [[UIView alloc]initWithFrame:CGRectMake(Screen_Width * i, 0, _mainScrollView.frame.size.width, _mainScrollView.frame.size.height - 100)];
  215. [pageView addSubview:views[i]];
  216. [_mainScrollView addSubview:pageView];
  217. }
  218. _mainScrollView.contentSize = CGSizeMake(Screen_Width*(views.count), 0);
  219. //滚动到_currentIndex对应的tab
  220. [_mainScrollView setContentOffset:CGPointMake((_mainScrollView.frame.size.width)*_currentIndex, 0) animated:YES];
  221. }
  222. @end