VipLessonViewController.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // VipLessonViewController.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2019/6/26.
  6. // Copyright © 2019 JCZ. All rights reserved.
  7. //
  8. #import "VipLessonViewController.h"
  9. #import "VipLessonTableHeaderView.h"
  10. #import "VipLessonContentViewController.h"
  11. @interface VipLessonViewController () <YNPageViewControllerDelegate, YNPageViewControllerDataSource>
  12. @end
  13. @implementation VipLessonViewController
  14. #pragma mark - Life Circle
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. [self initUI];
  18. NSFileManager*fileManager =[NSFileManager defaultManager];
  19. NSError*error;
  20. if( [fileManager fileExistsAtPath:[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"dyhapp.db"]]]== NO){
  21. NSString*resourcePath =[[NSBundle mainBundle] pathForResource:@"dyhapp" ofType:@"db"];
  22. [fileManager copyItemAtPath:resourcePath toPath:[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"dyhapp.db"]] error:&error];
  23. }
  24. }
  25. #pragma mark - Public Function
  26. + (instancetype)suspendCenterPageVC {
  27. YNPageConfigration *configration = [YNPageConfigration defaultConfig];
  28. configration.pageStyle = YNPageStyleSuspensionTopPause;
  29. configration.headerViewCouldScale = YES;
  30. configration.headerViewScaleMode = YNPageHeaderViewScaleModeTop;
  31. configration.showNavigation = YES;
  32. configration.scrollMenu = NO;
  33. configration.aligmentModeCenter = NO;
  34. /// Item
  35. configration.selectedItemColor = UIColor.blackColor;
  36. configration.normalItemColor = UIColor.lightGrayColor;
  37. configration.itemFont = [UIFont systemFontOfSize:17];
  38. configration.selectedItemFont = [UIFont systemFontOfSize:17];
  39. /// bottomLine
  40. configration.showBottomLine = YES;
  41. configration.bottomLineBgColor = UIColor.groupTableViewBackgroundColor;
  42. configration.bottomLineHeight = .5;
  43. /// line
  44. configration.lineColor = defGreen;
  45. configration.lineHeight = 3;
  46. configration.lineWidthEqualFontWidth = true;
  47. return [self suspendCenterPageVCWithConfig:configration];
  48. }
  49. + (NSArray *)getArrayVCs {
  50. VipLessonContentViewController *firstVC = [[VipLessonContentViewController alloc] init];
  51. VipLessonContentViewController *secondVC = [[VipLessonContentViewController alloc] init];
  52. return @[firstVC, secondVC];
  53. }
  54. + (NSArray *)getArrayTitles {
  55. return @[@"科目一", @"科目四"];
  56. }
  57. + (instancetype)suspendCenterPageVCWithConfig:(YNPageConfigration *)config {
  58. VipLessonViewController *vc = [VipLessonViewController pageViewControllerWithControllers:[self getArrayVCs]
  59. titles:[self getArrayTitles]
  60. config:config];
  61. vc.dataSource = vc;
  62. vc.delegate = vc;
  63. // VipLessonTableHeaderView *headerView = [[NSBundle mainBundle] loadNibNamed:@"VipLessonTableHeaderView" owner:self options:nil].firstObject;
  64. // [RACObserve(headerView.notVipView, hidden) subscribeNext:^(id x) {
  65. // if (headerView.notVipView.hidden) {
  66. // headerView.frame = CGRectMake(0, 0, kScreenWidth, kScreenWidth * 0.53);
  67. // }else {
  68. // headerView.frame = CGRectMake(0, 0, kScreenWidth, kScreenWidth * (737.f / 1080.f));
  69. // }
  70. // vc.headerView = headerView;
  71. // [vc reloadSuspendHeaderViewFrame];
  72. // }];
  73. /// 指定默认选择index 页面
  74. vc.pageIndex = 0;
  75. return vc;
  76. }
  77. #pragma mark - Private Functions
  78. - (void)initUI {
  79. /// 导航栏设置
  80. self.title = @"VIP课程";
  81. [self configNavigationBar];
  82. }
  83. #pragma mark - YNPageViewControllerDataSource
  84. - (UIScrollView *)pageViewController:(YNPageViewController *)pageViewController pageForIndex:(NSInteger)index {
  85. UIViewController *vc = pageViewController.controllersM[index];
  86. if ([vc isKindOfClass:[VipLessonContentViewController class]]) {
  87. return [(VipLessonContentViewController *)vc collectionView];
  88. }else {
  89. return nil;
  90. }
  91. }
  92. #pragma mark - YNPageViewControllerDelegate
  93. - (void)pageViewController:(YNPageViewController *)pageViewController
  94. contentOffsetY:(CGFloat)contentOffset
  95. progress:(CGFloat)progress {
  96. // NSLog(@"--- contentOffset = %f, progress = %f", contentOffset, progress);
  97. }
  98. /// 返回列表的高度 默认是控制器的高度大小
  99. - (CGFloat)pageViewController:(YNPageViewController *)pageViewController heightForScrollViewAtIndex:(NSInteger)index {
  100. return kScreenHeight + (kScreenWidth * 0.53) + kScreenHeight;
  101. }
  102. - (void)pageViewController:(YNPageViewController *)pageViewController didScrollMenuItem:(UIButton *)itemButton index:(NSInteger)index {
  103. NSLog(@"didScrollMenuItem index %ld", index);
  104. }
  105. @end