猎豆优选

LDCollectionViewController.m 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // LDCollectionViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/24.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDCollectionViewController.h"
  9. #import "LDTypeButtonHeader.h"
  10. #import "LDCollectionTicketController.h"
  11. #import "LDCollectionGoodsController.h"
  12. #import "MLMSegmentHead.h"
  13. #import "MLMSegmentManager.h"
  14. @interface LDCollectionViewController ()<UIScrollViewDelegate,MLMSegmentHeadDelegate>
  15. @property (nonatomic, strong) UIScrollView *scrollView;
  16. @property (nonatomic, strong) MLMSegmentHead *titleView;
  17. @property (nonatomic, strong) NSArray *childVCArr;
  18. @property (nonatomic, assign) NSInteger currentIndex;
  19. @end
  20. @implementation LDCollectionViewController
  21. - (void)viewWillAppear:(BOOL)animated {
  22. [super viewWillAppear:animated];
  23. [self.view bringSubviewToFront:self.navigationBar];
  24. }
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. [self configNavigtionBar];
  28. [self configChildViewController];
  29. }
  30. - (void)configNavigtionBar {
  31. // UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  32. // [leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
  33. // [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  34. // [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  35. self.navigationBar.showNavigationBarBottomLine = YES;
  36. NSArray *list = @[@"收藏的券",@"收藏的商品"];
  37. self.titleView = [[MLMSegmentHead alloc] initWithFrame:CGRectMake(50, NavBarHeight-44, SCREEN_WIDTH-100, 44) titles:list headStyle:SegmentHeadStyleLine layoutStyle:MLMSegmentLayoutCenter];
  38. self.titleView.headColor = [UIColor clearColor];
  39. self.titleView.fontScale = 1;
  40. self.titleView.fontSize = 14;
  41. self.titleView.lineScale = .8;
  42. self.titleView.equalSize = YES;
  43. self.titleView.bottomLineHeight = 0;
  44. self.titleView.lineColor = [UIColor homeRedColor];
  45. self.titleView.delegate = self;
  46. self.titleView.selectColor = [UIColor homeRedColor];
  47. self.titleView.deSelectColor = [UIColor YHColorWithHex:0x666666];
  48. [MLMSegmentManager associateHead:self.titleView withScroll:nil completion:^{
  49. [self.navigationBar addSubview:self.titleView];
  50. self.titleView.centerX = self.navigationBar.centerX;
  51. }];
  52. }
  53. - (void)configChildViewController {
  54. LDCollectionTicketController *ticket = [[LDCollectionTicketController alloc] init];
  55. [self.view addSubview:ticket.view];
  56. [self addChildViewController:ticket];
  57. ticket.view.y = NavBarHeight;
  58. LDCollectionGoodsController *goods = [[LDCollectionGoodsController alloc] init];
  59. [self.view insertSubview:goods.view belowSubview:ticket.view];
  60. [self addChildViewController:goods];
  61. goods.view.y = NavBarHeight;
  62. self.currentIndex = 0;
  63. self.childVCArr = @[ticket,goods];
  64. }
  65. - (void)backAction {
  66. [self.navigationController popViewControllerAnimated:YES];
  67. }
  68. #pragma mark --------------------- MLMSegmentHeadDelegate ---------
  69. - (void)didSelectedIndex:(NSInteger)index {
  70. [self transitionFromViewController:self.childVCArr[self.currentIndex] toViewController:self.childVCArr[index] duration:0.3 options:UIViewAnimationOptionCurveEaseOut animations:nil completion:^(BOOL finished) {
  71. self.currentIndex = index;
  72. }];
  73. }
  74. #pragma mark ------
  75. - (UIScrollView *)scrollView {
  76. if (!_scrollView) {
  77. _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight)];
  78. _scrollView.delegate = self;
  79. _scrollView.pagingEnabled = YES;
  80. }
  81. return _scrollView;
  82. }
  83. - (void)didReceiveMemoryWarning {
  84. [super didReceiveMemoryWarning];
  85. // Dispose of any resources that can be recreated.
  86. }
  87. /*
  88. #pragma mark - Navigation
  89. // In a storyboard-based application, you will often want to do a little preparation before navigation
  90. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  91. // Get the new view controller using [segue destinationViewController].
  92. // Pass the selected object to the new view controller.
  93. }
  94. */
  95. @end