NewOrderManagementViewController.m 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. //
  2. // NewOrderManagementViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2018/8/10.
  6. // Copyright © 2018年 罗云飞. All rights reserved.
  7. //
  8. #import "NewOrderManagementViewController.h"
  9. #import "SectionChooseView.h"
  10. #import "ServiceproviderViewController.h"//我是服务商
  11. #import "ConsumerViewController.h"//我是消费者
  12. @interface NewOrderManagementViewController ()<UIScrollViewDelegate,SectionChooseVCDelegate>{
  13. NSString *gender;//模拟性别区分
  14. UIView *navgationBar;
  15. }
  16. //底部滚动ScrollView
  17. @property (nonatomic, strong) UIScrollView *contentScrollView;
  18. @property(nonatomic,strong)SectionChooseView *sectionChooseView;
  19. @end
  20. @implementation NewOrderManagementViewController
  21. - (void)viewWillAppear:(BOOL)animated
  22. {
  23. [super viewWillAppear:animated];
  24. [self.navgationBar setHidden:YES];
  25. }
  26. - (void)viewDidDisappear:(BOOL)animated
  27. {
  28. [super viewDidDisappear:animated];
  29. [self.navgationBar setHidden:NO];
  30. }
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. // self.view.backgroundColor = NewRedColor;
  34. [self setNavTitle:@"订单列表"];
  35. [self loaddaohang];
  36. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showFirstVC) name:@"ABC" object:nil];
  37. // Do any additional setup after loading the view.
  38. // //添加所有子控制器
  39. [self setupChildViewController];
  40. //
  41. // //初始化UIScrollView
  42. [self setupUIScrollView];
  43. }
  44. - (void)loaddaohang{
  45. navgationBar = [[UIView alloc] init];
  46. [navgationBar setFrame:CGRectMake(0.0, 0.0, SCREEN_WIDTH, 110)];
  47. // [navgationBar setBackgroundColor:[UIColor colorWithString:@"#0097F4"]];
  48. UIView *statusView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, SCREEN_WIDTH, STATUSBAR_HEIGHT)];
  49. [statusView setBackgroundColor:[UIColor colorWithString:@"#0097F4"]];
  50. // [self.navgationBar addSubview:statusView];
  51. UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 110)];
  52. [imageview setImage:NewImageNamed(@"bit")];
  53. [navgationBar addSubview:imageview];
  54. // UIImage *backButtonImage = [[UIImage imageNamed:@"fh"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 0, 0)];
  55. UIButton *backButton= [UIButton buttonWithType:UIButtonTypeCustom];
  56. backButton.frame = CGRectMake(10, 27, 30, 30);
  57. [backButton setBackgroundColor:[UIColor clearColor]];
  58. // [backButton setBackgroundImage:NewImageNamed(@"fh") forState:UIControlStateNormal];
  59. [backButton setImage:NewImageNamed(@"fh") forState:UIControlStateNormal];
  60. [backButton addTarget:self action:@selector(popViewController) forControlEvents:UIControlEventTouchUpInside];
  61. [navgationBar addSubview:backButton];
  62. UILabel*navTitleLabel = [[UILabel alloc] init];
  63. [navTitleLabel setFrame:CGRectMake(SCREEN_WIDTH*0.2, 18.0, SCREEN_WIDTH*0.6, NAV_HEIGHT)];
  64. [navTitleLabel setBackgroundColor:NewClearColor];
  65. [navTitleLabel setTextAlignment:NSTextAlignmentCenter];
  66. [navTitleLabel setFont:NewBFont(18)];
  67. [navTitleLabel setTextColor:[UIColor whiteColor]];
  68. [navTitleLabel setText:@"我的订单"];
  69. [navgationBar addSubview:navTitleLabel];
  70. [self.view addSubview:navgationBar];
  71. }
  72. - (void)showFirstVC {
  73. [self showVc:0];
  74. }
  75. #pragma mark -添加所有子控制器
  76. -(void)setupChildViewController {
  77. ConsumerViewController *VC2 = [[ConsumerViewController alloc] init];
  78. VC2.type = self.dingdantype;
  79. [self addChildViewController:VC2];
  80. ServiceproviderViewController *VC1 = [[ServiceproviderViewController alloc] init];
  81. // VC1.type = self.dingdantype;
  82. [self addChildViewController:VC1];
  83. }
  84. - (void)setupUIScrollView {
  85. NSArray *arr1 = @[@"我是消费者", @"我是服务商"];
  86. // 创建底部滚动视图
  87. self.contentScrollView = [[UIScrollView alloc] init];
  88. _contentScrollView.frame = CGRectMake(0, NavHeader, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeader);
  89. _contentScrollView.contentSize = CGSizeMake(self.view.frame.size.width * arr1.count, 0);
  90. _contentScrollView.backgroundColor = [UIColor clearColor];
  91. // 开启分页
  92. _contentScrollView.pagingEnabled = YES;
  93. // 没有弹簧效果
  94. _contentScrollView.bounces = NO;
  95. // 隐藏水平滚动条
  96. _contentScrollView.showsHorizontalScrollIndicator = NO;
  97. // 设置代理
  98. _contentScrollView.delegate = self;
  99. [self.view addSubview:_contentScrollView];
  100. self.sectionChooseView = [[SectionChooseView alloc] initWithFrame:CGRectMake(0, NavHeader-1, self.view.frame.size.width, NavHeader) titleArray:arr1];
  101. self.sectionChooseView.selectIndex = 0;
  102. self.sectionChooseView.delegate = self;
  103. self.sectionChooseView.normalBackgroundColor = NewClearColor;
  104. self.sectionChooseView.selectBackgroundColor = [UIColor whiteColor];;
  105. self.sectionChooseView.titleNormalColor = [UIColor whiteColor];
  106. self.sectionChooseView.titleSelectColor = [UIColor colorWithString:@"#0097F4"];
  107. self.sectionChooseView.normalTitleFont = 16;
  108. self.sectionChooseView.selectTitleFont = 16;
  109. self.sectionChooseView.backgroundColor = NewClearColor;
  110. [self.view addSubview:self.sectionChooseView];
  111. }
  112. #pragma mark -SMCustomSegmentDelegate
  113. - (void)SectionSelectIndex:(NSInteger)selectIndex {
  114. NSLog(@"---------%ld",(long)selectIndex);
  115. // 1 计算滚动的位置
  116. CGFloat offsetX = selectIndex * self.view.frame.size.width;
  117. self.contentScrollView.contentOffset = CGPointMake(offsetX, 0);
  118. // 2.给对应位置添加对应子控制器
  119. [self showVc:selectIndex];
  120. }
  121. #pragma mark -显示控制器的view
  122. /**
  123. * 显示控制器的view
  124. *
  125. * @param index 选择第几个
  126. *
  127. */
  128. - (void)showVc:(NSInteger)index {
  129. CGFloat offsetX = index * self.view.frame.size.width;
  130. UIViewController *vc = self.childViewControllers[index];
  131. // 判断控制器的view有没有加载过,如果已经加载过,就不需要加载
  132. if (vc.isViewLoaded) return;
  133. [self.contentScrollView addSubview:vc.view];
  134. vc.view.frame = CGRectMake(offsetX, 0, self.view.frame.size.width, self.view.frame.size.height);
  135. }
  136. #pragma mark -UIScrollViewDelegate
  137. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
  138. // 计算滚动到哪一页
  139. NSInteger index = scrollView.contentOffset.x / scrollView.frame.size.width;
  140. // 1.添加子控制器view
  141. [self showVc:index];
  142. // 2.把对应的标题选中
  143. self.sectionChooseView.selectIndex = index;
  144. }
  145. - (void)didReceiveMemoryWarning {
  146. [super didReceiveMemoryWarning];
  147. // Dispose of any resources that can be recreated.
  148. }
  149. /*
  150. #pragma mark - Navigation
  151. // In a storyboard-based application, you will often want to do a little preparation before navigation
  152. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  153. // Get the new view controller using [segue destinationViewController].
  154. // Pass the selected object to the new view controller.
  155. }
  156. */
  157. @end