ZFViewController.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // ZFViewController.m
  3. // ZFPlayer_Example
  4. //
  5. // Created by 任子丰 on 2018/6/7.
  6. // Copyright © 2018年 紫枫. All rights reserved.
  7. //
  8. #import "ZFViewController.h"
  9. #import "ZFDouYinViewController.h"
  10. #import "ZFTableSectionModel.h"
  11. #import "ZFDouyinCollectionViewController.h"
  12. static NSString *kIdentifier = @"kIdentifier";
  13. @interface ZFViewController () <UITableViewDelegate,UITableViewDataSource>
  14. @property (nonatomic, strong) UITableView *tableView;
  15. @property (nonatomic, strong) NSMutableArray <ZFTableSectionModel *>*datas;
  16. @end
  17. @implementation ZFViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.navigationItem.title = @"ZFPlayer";
  21. [self.view addSubview:self.tableView];
  22. self.datas = @[].mutableCopy;
  23. [self.datas addObject:[ZFTableSectionModel sectionModeWithTitle:@"播放器样式(Player style)" items:[self createItemsByPlayerType]]];
  24. [self.datas addObject:[ZFTableSectionModel sectionModeWithTitle:@"UITableView样式(TableView style)" items:[self createItemsByTableView]]];
  25. [self.datas addObject:[ZFTableSectionModel sectionModeWithTitle:@"UICollectionView样式(CollectionView style)" items:[self createItemsByCollectionView]]];
  26. [self.datas addObject:[ZFTableSectionModel sectionModeWithTitle:@"旋转类型(Rotation type)" items:[self createItemsByRotationType]]];
  27. [self.datas addObject:[ZFTableSectionModel sectionModeWithTitle:@"自定义(Custom)" items:[self createItemsByCustom]]];
  28. // Temporarily disable third-party advertising demos
  29. // [self.datas addObject:[ZFTableSectionModel sectionModeWithTitle:@"其他(Other)" items:[self createItemsByOther]]];
  30. }
  31. - (NSArray <ZFTableItem *>*)createItemsByPlayerType {
  32. return @[[ZFTableItem itemWithTitle:@"普通样式,画中画" subTitle:@"Normal style" viewControllerName:@"ZFNormalViewController"],
  33. [ZFTableItem itemWithTitle:@"UITableView样式" subTitle:@"UITableView style" viewControllerName:@"ZFAutoPlayerViewController"],
  34. [ZFTableItem itemWithTitle:@"UICollectionView样式" subTitle:@"UICollectionView style" viewControllerName:@"ZFCollectionViewController"],
  35. [ZFTableItem itemWithTitle:@"UIScrollView样式" subTitle:@"UIScrollView style" viewControllerName:@"ZFScrollViewViewController"]];
  36. }
  37. - (NSArray <ZFTableItem *>*)createItemsByTableView {
  38. return @[[ZFTableItem itemWithTitle:@"点击播放" subTitle:@"Click to play" viewControllerName:@"ZFNotAutoPlayViewController"],
  39. [ZFTableItem itemWithTitle:@"自动播放" subTitle:@"Auto play" viewControllerName:@"ZFAutoPlayerViewController"],
  40. [ZFTableItem itemWithTitle:@"列表明暗播放" subTitle:@"Light and dark style" viewControllerName:@"ZFLightTableViewController"],
  41. [ZFTableItem itemWithTitle:@"微信朋友圈" subTitle:@"wechat friend circle style" viewControllerName:@"ZFWChatViewController"],
  42. [ZFTableItem itemWithTitle:@"混合cell样式" subTitle:@"Mix cell style" viewControllerName:@"ZFMixViewController"],
  43. [ZFTableItem itemWithTitle:@"小窗播放" subTitle:@"Small view style" viewControllerName:@"ZFSmallPlayViewController"],
  44. [ZFTableItem itemWithTitle:@"抖音样式" subTitle:@"Douyin style" viewControllerName:@"ZFDouYinViewController"],
  45. [ZFTableItem itemWithTitle:@"HeaderView样式" subTitle:@"Table header style" viewControllerName:@"ZFTableHeaderViewController"]];
  46. }
  47. - (NSArray <ZFTableItem *>*)createItemsByCollectionView {
  48. return @[[ZFTableItem itemWithTitle:@"抖音个人主页" subTitle:@"Douyin homepage" viewControllerName:@"ZFCollectionViewListController"],
  49. [ZFTableItem itemWithTitle:@"横向滚动抖音" subTitle:@"Horizontal Douyin style" viewControllerName:@"ZFDouyinCollectionViewController"],
  50. [ZFTableItem itemWithTitle:@"竖向滚动抖音" subTitle:@"Vertical Douyin style" viewControllerName:@"ZFDouyinCollectionViewController"],
  51. [ZFTableItem itemWithTitle:@"横向滚动CollectionView" subTitle:@"Horizontal CollectionView" viewControllerName:@"ZFHorizontalCollectionViewController"]];
  52. }
  53. - (NSArray <ZFTableItem *>*)createItemsByRotationType {
  54. return @[[ZFTableItem itemWithTitle:@"旋转类型" subTitle:@"Rotation type" viewControllerName:@"ZFRotationViewController"],
  55. [ZFTableItem itemWithTitle:@"旋转键盘" subTitle:@"Rotation keyboard" viewControllerName:@"ZFKeyboardViewController"],
  56. [ZFTableItem itemWithTitle:@"全屏播放" subTitle:@"Fullscreen play" viewControllerName:@"ZFFullScreenViewController"]];
  57. }
  58. - (NSArray <ZFTableItem *>*)createItemsByCustom {
  59. return @[[ZFTableItem itemWithTitle:@"自定义控制层" subTitle:@"Custom ControlView" viewControllerName:@"ZFCustomControlViewViewController"]];
  60. }
  61. #if 0 // Temporarily disable third-party advertising demos
  62. - (NSArray <ZFTableItem *>*)createItemsByOther {
  63. return @[[ZFTableItem itemWithTitle:@"广告" subTitle:@"Advertising" viewControllerName:@"ZFADViewController"]];
  64. }
  65. #endif
  66. - (void)viewWillLayoutSubviews {
  67. [super viewWillLayoutSubviews];
  68. self.tableView.frame = self.view.bounds;
  69. }
  70. - (BOOL)shouldAutorotate {
  71. return NO;
  72. }
  73. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  74. return UIInterfaceOrientationMaskPortrait;
  75. }
  76. #pragma mark - UITableViewDataSource
  77. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  78. return self.datas.count;
  79. }
  80. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  81. return self.datas[section].items.count;
  82. }
  83. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  84. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kIdentifier];
  85. cell.textLabel.font = [UIFont systemFontOfSize:15];
  86. ZFTableItem *itme = self.datas[indexPath.section].items[indexPath.row];
  87. cell.textLabel.text = [NSString stringWithFormat:@"%@(%@)",itme.title,itme.subTitle];
  88. return cell;
  89. }
  90. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  91. return self.datas[section].title;
  92. }
  93. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  94. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  95. ZFTableItem *itme = self.datas[indexPath.section].items[indexPath.row];
  96. NSString *vcString = itme.viewControllerName;
  97. UIViewController *viewController = [[NSClassFromString(vcString) alloc] init];
  98. if ([vcString isEqualToString:@"ZFDouYinViewController"]) {
  99. [(ZFDouYinViewController *)viewController playTheIndex:0];
  100. }
  101. viewController.navigationItem.title = itme.title;
  102. viewController.hidesBottomBarWhenPushed = YES;
  103. if ([vcString isEqualToString:@"ZFDouyinCollectionViewController"] && [itme.title isEqualToString:@"横向滚动抖音"]) {
  104. ZFDouyinCollectionViewController *douyinVC = (ZFDouyinCollectionViewController *)viewController;
  105. douyinVC.scrollViewDirection = ZFPlayerScrollViewDirectionHorizontal;
  106. }
  107. if ([vcString isEqualToString:@"ZFFullScreenViewController"]) {
  108. viewController.modalPresentationStyle = UIModalPresentationFullScreen;
  109. [self.navigationController presentViewController:viewController animated:NO completion:nil];
  110. } else {
  111. [self.navigationController pushViewController:viewController animated:YES];
  112. }
  113. }
  114. - (UITableView *)tableView {
  115. if (!_tableView) {
  116. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  117. [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kIdentifier];
  118. _tableView.delegate = self;
  119. _tableView.dataSource = self;
  120. _tableView.rowHeight = 44;
  121. }
  122. return _tableView;
  123. }
  124. @end