HomeViewController.m 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  1. //
  2. // HomeViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/17.
  6. //
  7. #import "HomeViewController.h"
  8. #import "KSBaseWKWebViewController.h"
  9. #import "NoticeMessageViewController.h"
  10. #import "SubjectChooseViewController.h"
  11. #import "HomeNavView.h"
  12. #import "HomeBannerView.h"
  13. #import <UIButton+WebCache.h>
  14. #import "TYCyclePagerView.h"
  15. #import "TYPageControl.h"
  16. #import "HomeBannerCell.h"
  17. #import "HomeBannerView.h"
  18. #import "HomeBannerCell.h"
  19. #import "HomeButtonView.h"
  20. #import "KSHomeButton.h"
  21. #import "HomeHotAlbumView.h"
  22. #import "HomeHotAlbumCell.h"
  23. #import "HomeAlbumModel.h"
  24. #import "HomeHotCourseView.h"
  25. #import "HomeIntroduceView.h"
  26. #import "TeacherShowCell.h"
  27. #import "HotInformationHeadView.h"
  28. #import "TeacherStyleModel.h"
  29. #import "HomeInformationCell.h"
  30. #import "HomeMessageModel.h"
  31. #import "StudentInfoModel.h"
  32. #import "UserInfoManager.h"
  33. #import "HomeCourseTipsView.h"
  34. #import "HomeLiveCouseCell.h"
  35. #import "HomeLiveGroupModel.h"
  36. #import "HomeVideoCourseCell.h"
  37. #import "HomeVideoGroupModel.h"
  38. #import "WMPlayer.h" // 播放相关
  39. #define BUTTONWIDTH (80)
  40. #define BUTTONHEIGHT (80)
  41. @interface HomeViewController ()<TYCyclePagerViewDataSource,TYCyclePagerViewDelegate,UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate,UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,WMPlayerDelegate>
  42. {
  43. WMPlayer *_wmPlayer;
  44. CGRect _playerFrame;
  45. }
  46. @property (nonatomic, strong) UIView *bgView;
  47. @property (nonatomic, assign) BOOL isRatation;
  48. @property (nonatomic, strong) UITableView *tableView;
  49. @property (nonatomic, strong) HomeNavView *navView;
  50. @property (nonatomic, strong) UIView *tableHeaderView; // headView;
  51. @property (nonatomic, strong) TYPageControl *pageControl;
  52. @property (nonatomic, strong) HomeBannerView *bannerView; // banner container
  53. @property (nonatomic, strong) TYCyclePagerView *bannerScroll; // 活动
  54. @property (nonatomic, strong) NSMutableArray *bannerArray; // banner 数据
  55. @property (nonatomic, assign) CGFloat bannerViewHeight; // banner 高度
  56. @property (nonatomic, strong) HomeButtonView *buttonContainer; // button container
  57. @property (nonatomic, strong) UIScrollView *buttonScrollView;
  58. @property (nonatomic, strong) NSMutableArray *buttonArray; // button 内容
  59. @property (nonatomic, assign) NSInteger buttonDotWidth;
  60. @property (nonatomic, assign) CGFloat buttonViewHeight; // button view 高度
  61. @property (nonatomic, strong) HomeHotAlbumView *albumView; // albumView container
  62. @property (nonatomic, strong) NSMutableArray *albumArray; // 热门专辑
  63. @property (nonatomic, strong) UICollectionView *albumCollectionView; // 专辑容器
  64. @property (nonatomic, assign) CGFloat albumViewHeight; // album 高度
  65. @property (nonatomic, strong) HomeHotCourseView *courseView; // course container
  66. @property (nonatomic, strong) UIScrollView *courseScroll; // 课程scroll
  67. @property (nonatomic, strong) UITableView *liveCourseTable; // 直播课table
  68. @property (nonatomic, strong) UITableView *videoCourseTable; // 视频课table
  69. @property (nonatomic, strong) NSMutableArray *videoCourseArray;
  70. @property (nonatomic, strong) NSMutableArray *liveCourseArray;
  71. @property (nonatomic, assign) CGFloat courseViewHeight;
  72. @property (nonatomic, strong) HomeIntroduceView *teacherView; // teacher container
  73. @property (nonatomic, strong) UICollectionView *infoCollectionView; // 老师风采简介
  74. @property (nonatomic, strong) NSMutableArray *teacherArray;
  75. @property (nonatomic, assign) CGFloat teachViewHeight;
  76. @property (nonatomic, strong) HotInformationHeadView *informationHeadView; // information Header
  77. @property (nonatomic, assign) CGFloat informationHeight;
  78. @property (nonatomic, strong) StudentInfoModel *mineInfo;
  79. @property (nonatomic, assign) BOOL hasCourseTips;
  80. @property (nonatomic, strong) HomeCourseTipsView *tipsCourseView;
  81. @property (nonatomic, assign) CGFloat tipsViewHeight;
  82. @property (nonatomic, assign) BOOL isChooseLive; // 是否选择直播课
  83. @property (nonatomic, assign) NSInteger courseCount;
  84. @end
  85. @implementation HomeViewController
  86. - (void)viewDidLoad {
  87. [super viewDidLoad];
  88. // Do any additional setup after loading the view.
  89. self.ks_prefersNavigationBarHidden = YES;
  90. self.isChooseLive = YES;
  91. [self configNavView];
  92. [self configUI];
  93. [self requestData];
  94. }
  95. - (void)viewWillAppear:(BOOL)animated {
  96. [super viewWillAppear:animated];
  97. }
  98. - (void)configNavView {
  99. [self.scrollView removeFromSuperview];
  100. [self.view addSubview:self.navView];
  101. [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.left.right.top.mas_equalTo(self.view);
  103. make.height.mas_equalTo(kNaviBarHeight);
  104. }];
  105. }
  106. - (void)configUI {
  107. [self.scrollView removeFromSuperview];
  108. [self.view addSubview:self.tableView];
  109. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.left.right.bottom.mas_equalTo(self.view);
  111. make.top.mas_equalTo(self.navView.mas_bottom);
  112. }];
  113. if (@available(iOS 11.0, *)) {
  114. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  115. } else {
  116. // Fallback on earlier versions
  117. self.automaticallyAdjustsScrollViewInsets = NO;
  118. }
  119. self.tableView.tableHeaderView = self.tableHeaderView;
  120. MJWeakSelf;
  121. self.tableView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
  122. [weakSelf requestData];
  123. }];
  124. // 配置 首页显示
  125. [self addDisplayView];
  126. }
  127. - (void)addDisplayView {
  128. CGFloat tableHeaderHeight = 0.0f;
  129. [self.tableHeaderView addSubview:self.bannerView];
  130. // banner
  131. self.bannerViewHeight = [HomeBannerView getViewHeight];
  132. tableHeaderHeight += self.bannerViewHeight;
  133. [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
  134. make.left.right.mas_equalTo(self.tableHeaderView);
  135. make.top.mas_equalTo(self.tableHeaderView.mas_top);
  136. make.height.mas_equalTo(self.bannerViewHeight);
  137. }];
  138. // button
  139. [self.tableHeaderView addSubview:self.buttonContainer];
  140. self.buttonViewHeight = [HomeButtonView getViewHeight];
  141. [self.buttonContainer mas_makeConstraints:^(MASConstraintMaker *make) {
  142. make.left.right.mas_equalTo(self.tableHeaderView);
  143. make.top.mas_equalTo(self.bannerView.mas_bottom);
  144. make.height.mas_equalTo(self.buttonViewHeight);
  145. }];
  146. tableHeaderHeight += self.buttonViewHeight;
  147. // 课程提醒
  148. [self.tableHeaderView addSubview:self.tipsCourseView];
  149. self.tipsViewHeight = CGFLOAT_MIN;
  150. self.tipsCourseView.hidden = YES;
  151. [self.tipsCourseView mas_makeConstraints:^(MASConstraintMaker *make) {
  152. make.left.right.mas_equalTo(self.tableHeaderView);
  153. make.top.mas_equalTo(self.buttonContainer.mas_bottom);
  154. make.height.mas_equalTo(self.tipsViewHeight);
  155. }];
  156. tableHeaderHeight += self.tipsViewHeight;
  157. // 专辑
  158. [self.tableHeaderView addSubview:self.albumView];
  159. self.albumViewHeight = [HomeHotAlbumView getViewHeight];
  160. [self.albumView mas_makeConstraints:^(MASConstraintMaker *make) {
  161. make.left.right.mas_equalTo(self.tableHeaderView);
  162. make.top.mas_equalTo(self.tipsCourseView.mas_bottom);
  163. make.height.mas_equalTo(self.albumViewHeight);
  164. }];
  165. tableHeaderHeight += self.albumViewHeight;
  166. // 课程
  167. [self.tableHeaderView addSubview:self.courseView];
  168. self.courseViewHeight = [self.courseView getViewHeightWithCount:10];
  169. [self.courseView mas_makeConstraints:^(MASConstraintMaker *make) {
  170. make.left.right.mas_equalTo(self.tableHeaderView);
  171. make.top.mas_equalTo(self.albumView.mas_bottom);
  172. make.height.mas_equalTo(self.courseViewHeight);
  173. }];
  174. self.courseScroll.contentSize = CGSizeMake(KPortraitWidth * 2, self.courseViewHeight - 59);
  175. [self.courseScroll addSubview:self.liveCourseTable];
  176. [self.liveCourseTable mas_makeConstraints:^(MASConstraintMaker *make) {
  177. make.left.mas_equalTo(self.courseScroll);
  178. make.top.bottom.mas_equalTo(self.courseView.courseContainer);
  179. make.width.mas_equalTo(KPortraitWidth);
  180. }];
  181. [self.courseScroll addSubview:self.videoCourseTable];
  182. [self.videoCourseTable mas_makeConstraints:^(MASConstraintMaker *make) {
  183. make.left.mas_equalTo(_courseScroll.mas_left).offset(KPortraitWidth);
  184. make.top.bottom.mas_equalTo(self.courseView.courseContainer);
  185. make.width.mas_equalTo(KPortraitWidth);
  186. }];
  187. tableHeaderHeight += self.courseViewHeight;
  188. // 老师风采
  189. [self.tableHeaderView addSubview:self.teacherView];
  190. self.teachViewHeight = [self.teacherView getViewHeightWithSourceCount:10];
  191. [self.teacherView mas_makeConstraints:^(MASConstraintMaker *make) {
  192. make.left.right.mas_equalTo(self.tableHeaderView);
  193. make.top.mas_equalTo(self.courseView.mas_bottom);
  194. make.height.mas_equalTo(self.teachViewHeight);
  195. }];
  196. tableHeaderHeight += self.teachViewHeight;
  197. [self.tableHeaderView addSubview:self.informationHeadView];
  198. self.informationHeight = [HotInformationHeadView getViewHeight];
  199. [self.informationHeadView mas_remakeConstraints:^(MASConstraintMaker *make) {
  200. make.left.right.mas_equalTo(self.tableHeaderView);
  201. make.top.mas_equalTo(self.teacherView.mas_bottom);
  202. make.height.mas_equalTo(self.informationHeight);
  203. }];
  204. tableHeaderHeight += self.informationHeight;
  205. self.tableHeaderView.frame = CGRectMake(0, 0, KPortraitWidth, tableHeaderHeight);
  206. }
  207. - (void)refreshTableHeadHeight {
  208. CGFloat tableHeaderHeight = self.bannerViewHeight + self.buttonViewHeight + self.tipsViewHeight + self.albumViewHeight + self.courseViewHeight + self.teachViewHeight + self.informationHeight;
  209. self.tableHeaderView.frame = CGRectMake(0, 0, KPortraitWidth, tableHeaderHeight);
  210. [self.tableView reloadData];
  211. }
  212. - (void)requestData {
  213. [self requestUserInfo]; // 获取老师声部
  214. [self requestNewsList]; //
  215. [self requestCourseInfo];
  216. [self requestTeacherStyle];
  217. [self requestHotAlbum];
  218. }
  219. - (void)requestNewsList {
  220. }
  221. - (void)requestHotAlbum {
  222. [KSNetworkingManager HomeHotAlbumRequest:KS_POST page:1 rows:10 success:^(NSDictionary * _Nonnull dic) {
  223. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  224. NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
  225. NSMutableArray *albumArray = [NSMutableArray array];
  226. for (NSDictionary *parm in sourceArray) {
  227. HomeAlbumModel *model = [[HomeAlbumModel alloc] initWithDictionary:parm];
  228. [albumArray addObject:model];
  229. }
  230. self.albumArray = [NSMutableArray arrayWithArray:albumArray];
  231. }
  232. else {
  233. [self MBPShow:MESSAGEKEY];
  234. }
  235. [self refreshAlbumView];
  236. } faliure:^(NSError * _Nonnull error) {
  237. }];
  238. }
  239. - (void)refreshAlbumView {
  240. if (self.albumArray.count) {
  241. self.albumViewHeight = [HomeHotAlbumView getViewHeight];
  242. self.albumView.hidden = NO;
  243. }
  244. else {
  245. self.albumViewHeight = CGFLOAT_MIN;
  246. self.albumView.hidden = YES;
  247. }
  248. [self.albumView mas_updateConstraints:^(MASConstraintMaker *make) {
  249. make.height.mas_equalTo(self.albumViewHeight);
  250. }];
  251. [self.albumCollectionView reloadData];
  252. [self refreshTableHeadHeight];
  253. }
  254. - (void)requestCourseInfo {
  255. [KSNetworkingManager homeQueryLiveAndVideo:KS_GET success:^(NSDictionary * _Nonnull dic) {
  256. [self.tableView.mj_header endRefreshing];
  257. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  258. NSDictionary *sourceDic = [dic dictionaryValueForKey:@"data"];
  259. NSArray *liveList = [sourceDic arrayValueForKey:@"liveList"];
  260. NSMutableArray *liveCourse = [NSMutableArray array];
  261. for (NSDictionary *parm in liveList) {
  262. HomeLiveGroupModel *model = [[HomeLiveGroupModel alloc] initWithDictionary:parm];
  263. [liveCourse addObject:model];
  264. }
  265. self.liveCourseArray = [NSMutableArray arrayWithArray:liveCourse];
  266. NSArray *videoList = [sourceDic arrayValueForKey:@"videoList"];
  267. NSMutableArray *videoCourse = [NSMutableArray array];
  268. for (NSDictionary *parm in videoList) {
  269. HomeVideoGroupModel *model = [[HomeVideoGroupModel alloc] initWithDictionary:parm];
  270. [videoCourse addObject:model];
  271. }
  272. self.videoCourseArray = [NSMutableArray arrayWithArray:videoCourse];
  273. }
  274. else {
  275. [self MBPShow:MESSAGEKEY];
  276. }
  277. [self refreshCourseView];
  278. } faliure:^(NSError * _Nonnull error) {
  279. [self.tableView.mj_header endRefreshing];
  280. }];
  281. }
  282. - (void)refreshCourseView {
  283. // 课程
  284. if (self.liveCourseArray.count && self.videoCourseArray.count) {
  285. self.courseCount = self.liveCourseArray.count >= self.videoCourseArray.count ? self.videoCourseArray.count : self.liveCourseArray.count;
  286. // 根据课程返回数据显示高度
  287. self.courseViewHeight = [self.courseView getViewHeightWithCount:self.courseCount];
  288. }
  289. else {
  290. self.courseViewHeight = CGFLOAT_MIN;
  291. }
  292. [self.courseView mas_updateConstraints:^(MASConstraintMaker *make) {
  293. make.height.mas_equalTo(self.courseViewHeight);
  294. }];
  295. [self.liveCourseTable reloadData];
  296. [self.videoCourseTable reloadData];
  297. [self refreshTableHeadHeight];
  298. }
  299. - (void)requestUserInfo {
  300. [KSNetworkingManager queryStudentInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  301. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  302. self.mineInfo = [[StudentInfoModel alloc] initWithDictionary:[dic dictionaryValueForKey:@"data"]];
  303. NSString *rongToken = UserDefault(RongTokenKey);
  304. if ([NSString isEmptyString:rongToken]) {
  305. [USER_MANAGER queryUserInfoConnectRongCloud:YES];
  306. }
  307. [self refreshNavView];
  308. }
  309. else {
  310. [self MBPShow:MESSAGEKEY];
  311. }
  312. } faliure:^(NSError * _Nonnull error) {
  313. }];
  314. }
  315. - (void)requestTeacherStyle {
  316. [KSNetworkingManager homeQueryTeacherStyle:KS_POST page:1 rows:10 success:^(NSDictionary * _Nonnull dic) {
  317. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  318. NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
  319. NSMutableArray *styleArray = [NSMutableArray array];
  320. for (NSDictionary *parm in sourceArray) {
  321. TeacherStyleModel *model = [[TeacherStyleModel alloc] initWithDictionary:parm];
  322. [styleArray addObject:model];
  323. }
  324. self.teacherArray = [NSMutableArray arrayWithArray:styleArray];
  325. }
  326. else {
  327. [self MBPShow:MESSAGEKEY];
  328. }
  329. // 回调
  330. [self refreshTeachView];
  331. } faliure:^(NSError * _Nonnull error) {
  332. }];
  333. }
  334. - (void)refreshTeachView {
  335. if (self.teacherArray.count) {
  336. self.teachViewHeight = [self.teacherView getViewHeightWithSourceCount:self.teacherArray.count];
  337. self.teacherView.hidden = NO;
  338. }
  339. else {
  340. self.teachViewHeight = CGFLOAT_MIN;
  341. self.teacherView.hidden = YES;
  342. }
  343. [self.teacherView mas_updateConstraints:^(MASConstraintMaker *make) {
  344. make.height.mas_equalTo(self.teachViewHeight);
  345. }];
  346. [self.infoCollectionView reloadData];
  347. [self refreshTableHeadHeight];
  348. }
  349. - (void)refreshNavView {
  350. NSString *subjectName = @"";
  351. if ([NSString isEmptyString:self.mineInfo.subjectName]) {
  352. subjectName = @"请选择乐器";
  353. }
  354. else {
  355. subjectName = self.mineInfo.subjectName;
  356. }
  357. self.navView.subjectName.text = subjectName;
  358. }
  359. - (void)refreshBannaerView {
  360. if (self.bannerArray.count > 1) {
  361. self.bannerScroll.autoScrollInterval = 3.0f;
  362. [self.bannerScroll addSubview:self.pageControl];
  363. }
  364. else {
  365. self.bannerScroll.autoScrollInterval = 0;
  366. [self.pageControl removeFromSuperview];
  367. }
  368. _pageControl.numberOfPages = self.bannerArray.count;
  369. [self.bannerScroll reloadData];
  370. }
  371. - (void)showButtonMessage {
  372. // 添加按钮
  373. if (self.buttonArray.count > 4) { // 大于4个显示底部滚动视图
  374. self.buttonContainer.buttonPageCtrl.hidden = NO;
  375. self.buttonContainer.buttonDotLeft.constant = 0;
  376. NSInteger addPage = (self.buttonArray.count % 4) > 0 ? 1 : 0;
  377. NSInteger pageCount = self.buttonArray.count / 4 + addPage;
  378. self.buttonDotWidth = 36 / pageCount;
  379. self.buttonContainer.buttonDotWidth.constant = self.buttonDotWidth;
  380. self.buttonScrollView.contentSize = CGSizeMake(kScreenWidth * pageCount, BUTTONHEIGHT);
  381. }
  382. else {
  383. self.buttonContainer.buttonPageCtrl.hidden = YES;
  384. self.buttonScrollView.contentSize = CGSizeMake(kScreenWidth, BUTTONHEIGHT);
  385. }
  386. self.buttonScrollView.contentOffset = CGPointMake(0, 0);
  387. [self.buttonScrollView removeAllSubViews];
  388. CGFloat buttonSpace = (kScreenWidth - 4 * BUTTONWIDTH) / 5;
  389. for (NSInteger i = 0; i < self.buttonArray.count; i++) {
  390. HomeMessageModel *model = self.buttonArray[i];
  391. KSHomeButton *buttonView = [KSHomeButton shareInstance];
  392. [buttonView.buttonImage sd_setImageWithURL:[NSURL URLWithString:model.coverImage]];
  393. buttonView.buttonTitle.text = model.title;
  394. buttonView.frame = CGRectMake(buttonSpace + (i % 4) * (BUTTONWIDTH + buttonSpace) + (i / 4) * KPortraitWidth, 0, BUTTONWIDTH, BUTTONHEIGHT);
  395. buttonView.actionButton.tag = 3000 + i;
  396. [buttonView.actionButton addTarget:self action:@selector(HomeTopButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  397. [self.buttonScrollView addSubview:buttonView];
  398. }
  399. }
  400. - (void)HomeTopButtonAction:(UIButton *)sender {
  401. NSInteger index = sender.tag - 3000;
  402. if ([self checkIsLoginToLoginView:YES]) {
  403. HomeMessageModel *model = self.buttonArray[index];
  404. if (![NSString isEmptyString:model.linkUrl]) {
  405. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  406. webCtrl.url = model.linkUrl;
  407. [self.navigationController pushViewController:webCtrl animated:YES];
  408. }
  409. }
  410. }
  411. #pragma mark - TYCyclePagerViewDataSource代理
  412. - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
  413. return self.bannerArray.count;
  414. }
  415. - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
  416. HomeMessageModel *model = self.bannerArray[index];
  417. HomeBannerCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"HomeBannerCell" forIndex:index];
  418. [cell configCellWithModel:model];
  419. return cell;
  420. }
  421. - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
  422. TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
  423. layout.itemSize = CGSizeMake(CGRectGetWidth(pageView.frame), CGRectGetHeight(pageView.frame));
  424. layout.itemSpacing = 0;
  425. return layout;
  426. }
  427. - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
  428. if (pageView == self.bannerScroll) {
  429. [self.pageControl setCurrentPage:toIndex animate:YES];
  430. }
  431. }
  432. - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index {
  433. HomeMessageModel *model = self.bannerArray[index];
  434. if (![NSString isEmptyString:model.linkUrl]) {
  435. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  436. webCtrl.url = model.linkUrl;
  437. [self.navigationController pushViewController:webCtrl animated:YES];
  438. }
  439. }
  440. #pragma mark ----- table data source
  441. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  442. if (tableView == self.tableView) { // 资讯
  443. return self.dataArray.count;
  444. }
  445. else if (tableView == self.liveCourseTable) { // 直播课列表
  446. return self.courseCount;
  447. }
  448. else { // 视频课列表
  449. return self.courseCount;
  450. }
  451. }
  452. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  453. if (tableView == self.tableView) {
  454. HomeMessageModel *model = self.dataArray[indexPath.row];
  455. HomeInformationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeInformationCell"];
  456. ROWINDEX rowIndex = ROWINDEX_MIDDLE;
  457. if (indexPath.row == 0) {
  458. rowIndex = ROWINDEX_TOP;
  459. }
  460. else if (indexPath.row == self.dataArray.count - 1) {
  461. rowIndex = ROWINDEX_BOTTOM;
  462. }
  463. [cell configCellWithSource:model rowIndex:rowIndex];
  464. return cell;
  465. }
  466. else if (tableView == self.liveCourseTable) {
  467. HomeLiveGroupModel *model = self.liveCourseArray[indexPath.row];
  468. HomeLiveCouseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeLiveCouseCell"];
  469. [cell configWithSource:model];
  470. return cell;
  471. }
  472. else {
  473. HomeVideoGroupModel *model = self.videoCourseArray[indexPath.row];
  474. HomeVideoCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeVideoCourseCell"];
  475. [cell configWithSource:model];
  476. return cell;
  477. }
  478. }
  479. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  480. if (tableView == self.tableView) {
  481. HomeMessageModel *model = self.dataArray[indexPath.row];
  482. if (![NSString isEmptyString:model.linkUrl]) {
  483. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  484. webCtrl.url = model.linkUrl;
  485. [self.navigationController pushViewController:webCtrl animated:YES];
  486. }
  487. }
  488. else if (tableView == self.liveCourseTable) { // 直播课详情
  489. HomeLiveGroupModel *model = self.liveCourseArray[indexPath.row];
  490. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  491. NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/liveDetail?groupId=",model.courseGroupId];
  492. ctrl.url = url;
  493. [self.navigationController pushViewController:ctrl animated:YES];
  494. }
  495. else if (tableView == self.videoCourseTable) { //
  496. HomeVideoGroupModel *model = self.videoCourseArray[indexPath.row];
  497. NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/videoDetail?groupId=",model.videoGroupId];
  498. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  499. ctrl.url = url;
  500. [self.navigationController pushViewController:ctrl animated:YES];
  501. }
  502. }
  503. #pragma mark ---- collection data source
  504. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  505. return 1;
  506. }
  507. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  508. if (collectionView == self.albumCollectionView) {
  509. return self.albumArray.count;
  510. }
  511. else { // 老师风采
  512. return self.teacherArray.count;
  513. }
  514. }
  515. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  516. if (collectionView == self.albumCollectionView) {
  517. HomeAlbumModel *model = self.albumArray[indexPath.item];
  518. HomeHotAlbumCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotAlbumCell" forIndexPath:indexPath];
  519. [cell configWithAlbumModel:model];
  520. return cell;
  521. }
  522. else {
  523. TeacherStyleModel *model = self.teacherArray[indexPath.item];
  524. TeacherShowCell *showCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TeacherShowCell" forIndexPath:indexPath];
  525. MJWeakSelf;
  526. [showCell configWithStyleModel:model callback:^(NSString *videoUrl) {
  527. [weakSelf playVideo:videoUrl];
  528. }];
  529. return showCell;
  530. }
  531. }
  532. - (void)playVideo:(NSString *)videoUrl {
  533. if ([NSString isEmptyString:videoUrl]) {
  534. return;
  535. }
  536. // 播放视频
  537. [self playVideoWithUrl:videoUrl];
  538. }
  539. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  540. if (collectionView == self.albumCollectionView) { // 专辑详情
  541. }
  542. else { // 老师风采详情
  543. TeacherStyleModel *model = self.teacherArray[indexPath.item];
  544. [self displayTeacherDetail:model.userId];
  545. }
  546. }
  547. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  548. if (collectionView == self.albumCollectionView) {
  549. return CGSizeMake(110, 140);
  550. }
  551. else {
  552. return CGSizeMake((KPortraitWidth - 28 - 11) / 2.0f, 164);
  553. }
  554. }
  555. // 老师风采
  556. - (void)displayTeacherDetail:(NSString *)teacherId {
  557. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  558. ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/teacherHome?teacherId=",teacherId];
  559. [self.navigationController pushViewController:ctrl animated:YES];
  560. }
  561. #pragma mark ---- scroll view delegate
  562. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  563. if (scrollView == self.buttonScrollView) {
  564. NSInteger index = (NSInteger)(scrollView.contentOffset.x / kScreenWidth);
  565. [UIView animateWithDuration:0.3f animations:^{
  566. self.buttonContainer.buttonDotLeft.constant = index * self.buttonDotWidth;
  567. }];
  568. }
  569. else if (scrollView == self.courseScroll) {
  570. }
  571. }
  572. #pragma mark ---- lazying
  573. - (NSMutableArray *)buttonArray {
  574. if (!_buttonArray) {
  575. _buttonArray = [NSMutableArray array];
  576. }
  577. return _buttonArray;
  578. }
  579. - (NSMutableArray *)bannerArray {
  580. if (!_bannerArray) {
  581. _bannerArray = [NSMutableArray array];
  582. }
  583. return _bannerArray;
  584. }
  585. - (NSMutableArray *)albumArray {
  586. if (!_albumArray) {
  587. _albumArray = [NSMutableArray array];
  588. }
  589. return _albumArray;
  590. }
  591. - (NSMutableArray *)liveCourseArray {
  592. if (!_liveCourseArray) {
  593. _liveCourseArray = [NSMutableArray array];
  594. }
  595. return _liveCourseArray;
  596. }
  597. - (NSMutableArray *)videoCourseArray {
  598. if (!_videoCourseArray) {
  599. _videoCourseArray = [NSMutableArray array];
  600. }
  601. return _videoCourseArray;
  602. }
  603. - (NSMutableArray *)teacherArray {
  604. if (!_teacherArray) {
  605. _teacherArray = [NSMutableArray array];
  606. }
  607. return _teacherArray;
  608. }
  609. #pragma mark ----- 最近上课
  610. - (HomeCourseTipsView *)tipsCourseView {
  611. if (!_tipsCourseView) {
  612. _tipsCourseView = [HomeCourseTipsView shareInstance];
  613. MJWeakSelf;
  614. [_tipsCourseView joinRoomCallback:^(COURSETYPE type, NSString * _Nonnull courseId) {
  615. [weakSelf joinRoomAction:type courseId:courseId];
  616. }];
  617. }
  618. return _tipsCourseView;
  619. }
  620. - (void)joinRoomAction:(COURSETYPE)type courseId:(NSString *)courseId {
  621. if (type == COURSETYPE_ACCOMPANY) { // 陪练课详情
  622. }
  623. else { // 直播课详情
  624. }
  625. }
  626. #pragma mark ----- 专辑
  627. - (HomeHotAlbumView *)albumView {
  628. if (!_albumView) {
  629. _albumView = [HomeHotAlbumView shareInstance];
  630. MJWeakSelf;
  631. [_albumView homeAlbumMore:^{
  632. [weakSelf moreAlbumDetail];
  633. }];
  634. [_albumView.albumContentView addSubview:self.albumCollectionView];
  635. [self.albumCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  636. make.left.right.bottom.top.mas_equalTo(_albumView.albumContentView);
  637. }];
  638. }
  639. return _albumView;
  640. }
  641. - (UICollectionView *)albumCollectionView {
  642. if (!_albumCollectionView) {
  643. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  644. layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
  645. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  646. _albumCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  647. _albumCollectionView.backgroundColor = [UIColor clearColor];
  648. _albumCollectionView.delegate = self;
  649. _albumCollectionView.dataSource = self;
  650. _albumCollectionView.showsVerticalScrollIndicator = NO;
  651. _albumCollectionView.showsHorizontalScrollIndicator = NO;
  652. [_albumCollectionView registerNib:[UINib nibWithNibName:@"HomeHotAlbumCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotAlbumCell"];
  653. }
  654. return _albumCollectionView;
  655. }
  656. - (void)moreAlbumDetail {
  657. return;
  658. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  659. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @""];
  660. [self.navigationController pushViewController:ctrl animated:YES];
  661. }
  662. #pragma mark ------ 推荐课程
  663. - (HomeHotCourseView *)courseView {
  664. if (!_courseView) {
  665. _courseView = [HomeHotCourseView shareInstance];
  666. MJWeakSelf;
  667. [_courseView courseActionCallback:^(COURSE_ACTION action) {
  668. [weakSelf homeCourseChooseAction:action];
  669. }];
  670. [_courseView.courseContainer addSubview:self.courseScroll];
  671. [self.courseScroll mas_makeConstraints:^(MASConstraintMaker *make) {
  672. make.left.right.bottom.top.mas_equalTo(_courseView.courseContainer);
  673. }];
  674. }
  675. return _courseView;
  676. }
  677. - (UIScrollView *)courseScroll {
  678. if (!_courseScroll) {
  679. _courseScroll = [[UIScrollView alloc] initWithFrame:CGRectZero];
  680. _courseScroll.pagingEnabled = YES;
  681. _courseScroll.scrollEnabled = NO;
  682. _courseScroll.showsHorizontalScrollIndicator = NO;
  683. _courseScroll.showsVerticalScrollIndicator = NO;
  684. _courseScroll.delegate = self;
  685. }
  686. return _courseScroll;
  687. }
  688. - (UITableView *)liveCourseTable {
  689. if (!_liveCourseTable) {
  690. _liveCourseTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  691. _liveCourseTable.delegate = self;
  692. _liveCourseTable.dataSource = self;
  693. _liveCourseTable.rowHeight = 126;
  694. _liveCourseTable.separatorStyle = UITableViewCellSeparatorStyleNone;
  695. _liveCourseTable.backgroundColor = [UIColor clearColor];
  696. _liveCourseTable.showsVerticalScrollIndicator = NO;
  697. [_liveCourseTable registerNib:[UINib nibWithNibName:@"HomeLiveCouseCell" bundle:nil] forCellReuseIdentifier:@"HomeLiveCouseCell"];
  698. _liveCourseTable.scrollEnabled = NO;
  699. }
  700. return _liveCourseTable;
  701. }
  702. - (UITableView *)videoCourseTable {
  703. if (!_videoCourseTable) {
  704. _videoCourseTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  705. _videoCourseTable.delegate = self;
  706. _videoCourseTable.dataSource = self;
  707. _videoCourseTable.rowHeight = 126;
  708. _videoCourseTable.separatorStyle = UITableViewCellSeparatorStyleNone;
  709. _videoCourseTable.backgroundColor = [UIColor clearColor];
  710. _videoCourseTable.showsVerticalScrollIndicator = NO;
  711. [_videoCourseTable registerNib:[UINib nibWithNibName:@"HomeVideoCourseCell" bundle:nil] forCellReuseIdentifier:@"HomeVideoCourseCell"];
  712. _videoCourseTable.scrollEnabled = NO;
  713. }
  714. return _videoCourseTable;
  715. }
  716. - (void)homeCourseChooseAction:(COURSE_ACTION)action {
  717. switch (action) {
  718. case COURSE_ACTION_LIVE:
  719. {
  720. if (self.isChooseLive == YES) {
  721. return;
  722. }
  723. self.isChooseLive = YES;
  724. }
  725. break;
  726. case COURSE_ACTION_VIDEO:
  727. {
  728. if (self.isChooseLive == NO) {
  729. return;
  730. }
  731. self.isChooseLive = NO;
  732. }
  733. break;
  734. case COURSE_ACTION_MORE: // 更多
  735. {
  736. NSString *url = @"";
  737. if (self.isChooseLive) { // 直播课 列表
  738. url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/liveClass"];
  739. }
  740. else { // 视频课列表
  741. url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/videoClass"];
  742. }
  743. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  744. ctrl.url = url;
  745. [self.navigationController pushViewController:ctrl animated:YES];
  746. }
  747. break;
  748. default:
  749. break;
  750. }
  751. }
  752. - (void)setIsChooseLive:(BOOL)isChooseLive {
  753. _isChooseLive = isChooseLive;
  754. // 切换
  755. [UIView animateWithDuration:0.3f animations:^{
  756. if (isChooseLive) {
  757. [self.courseScroll setContentOffset:CGPointZero animated:YES];
  758. }
  759. else {
  760. [self.courseScroll setContentOffset:CGPointMake(KPortraitWidth, 0) animated:YES];
  761. }
  762. }];
  763. }
  764. #pragma mark --- 老师风采
  765. - (HomeIntroduceView *)teacherView {
  766. if (!_teacherView) {
  767. _teacherView = [HomeIntroduceView shareInstance];
  768. MJWeakSelf;
  769. [_teacherView introduceMore:^{
  770. [weakSelf teacherMoreIntorduce];
  771. }];
  772. [_teacherView.teacherContainer addSubview:self.infoCollectionView];
  773. [self.infoCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  774. make.bottom.top.mas_equalTo(_teacherView.teacherContainer);
  775. make.left.mas_equalTo(_teacherView.mas_left).offset(14);
  776. make.right.mas_equalTo(_teacherView.mas_right).offset(-14);
  777. }];
  778. }
  779. return _teacherView;
  780. }
  781. - (void)teacherMoreIntorduce {
  782. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  783. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherList"];
  784. [self.navigationController pushViewController:ctrl animated:YES];
  785. }
  786. - (UICollectionView *)infoCollectionView {
  787. if (!_infoCollectionView) {
  788. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  789. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  790. _infoCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  791. _infoCollectionView.backgroundColor = [UIColor clearColor];
  792. _infoCollectionView.delegate = self;
  793. _infoCollectionView.dataSource = self;
  794. _infoCollectionView.showsVerticalScrollIndicator = NO;
  795. _infoCollectionView.showsHorizontalScrollIndicator = NO;
  796. [_infoCollectionView registerNib:[UINib nibWithNibName:@"TeacherShowCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"TeacherShowCell"];
  797. }
  798. return _infoCollectionView;
  799. }
  800. #pragma mark ---- button container
  801. - (HomeButtonView *)buttonContainer {
  802. if (!_buttonContainer) {
  803. _buttonContainer = [HomeButtonView shareInstance];
  804. [_buttonContainer.buttonContentView addSubview:self.buttonScrollView];
  805. }
  806. return _buttonContainer;
  807. }
  808. - (UIScrollView *)buttonScrollView {
  809. if (!_buttonScrollView) {
  810. _buttonScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, BUTTONHEIGHT)];
  811. _buttonScrollView.backgroundColor = [UIColor clearColor];
  812. _buttonScrollView.pagingEnabled = YES;
  813. _buttonScrollView.showsHorizontalScrollIndicator = NO;
  814. _buttonScrollView.showsVerticalScrollIndicator = NO;
  815. _buttonScrollView.delegate = self;
  816. }
  817. return _buttonScrollView;
  818. }
  819. - (UIView *)tableHeaderView {
  820. if (!_tableHeaderView) {
  821. _tableHeaderView = [[UIView alloc] initWithFrame:CGRectZero];
  822. _tableHeaderView.backgroundColor = [UIColor clearColor];
  823. }
  824. return _tableHeaderView;
  825. }
  826. - (HomeBannerView *)bannerView {
  827. if (!_bannerView) {
  828. _bannerView = [HomeBannerView shareInstance];
  829. [_bannerView.bannerContentView addSubview:self.bannerScroll];
  830. }
  831. return _bannerView;
  832. }
  833. - (TYCyclePagerView *)bannerScroll {
  834. if (!_bannerScroll) {
  835. _bannerScroll = [[TYCyclePagerView alloc] init];
  836. _bannerScroll.backgroundColor = [UIColor clearColor];
  837. _bannerScroll.frame = CGRectMake(0, 0, kScreenWidth - 28, (kScreenWidth - 28) / 347 * 132);
  838. _bannerScroll.isInfiniteLoop = YES;
  839. _bannerScroll.autoScrollInterval = 3.0f;
  840. _bannerScroll.reloadDataNeedResetIndex = YES;
  841. _bannerScroll.dataSource = self;
  842. _bannerScroll.delegate = self;
  843. [_bannerScroll registerNib:[UINib nibWithNibName:@"HomeBannerCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBannerCell"];
  844. }
  845. return _bannerScroll;
  846. }
  847. #pragma mark ---- 更多资讯
  848. - (HotInformationHeadView *)informationHeadView {
  849. if (!_informationHeadView) {
  850. _informationHeadView = [HotInformationHeadView shareInstance];
  851. MJWeakSelf;
  852. [_informationHeadView moreInformationCallback:^{
  853. [weakSelf moreInformation];
  854. }];
  855. }
  856. return _informationHeadView;
  857. }
  858. - (void)moreInformation {
  859. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  860. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherList"];
  861. [self.navigationController pushViewController:ctrl animated:YES];
  862. }
  863. - (UITableView *)tableView {
  864. if (!_tableView) {
  865. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  866. _tableView.delegate = self;
  867. _tableView.dataSource = self;
  868. _tableView.rowHeight = 108;
  869. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  870. _tableView.backgroundColor = [UIColor clearColor];
  871. _tableView.showsVerticalScrollIndicator = NO;
  872. [_tableView registerNib:[UINib nibWithNibName:@"HomeInformationCell" bundle:nil] forCellReuseIdentifier:@"HomeInformationCell"];
  873. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
  874. bottomView.backgroundColor = [UIColor clearColor];
  875. _tableView.tableFooterView = bottomView;
  876. }
  877. return _tableView;
  878. }
  879. - (HomeNavView *)navView {
  880. if (!_navView) {
  881. _navView = [HomeNavView shareInstance];
  882. MJWeakSelf;
  883. [_navView homeNavAction:^(NAVACTION action) {
  884. [weakSelf navAction:action];
  885. }];
  886. }
  887. return _navView;
  888. }
  889. - (void)navAction:(NAVACTION)action {
  890. if (action == NAVACTION_SUBJECT) {
  891. [self showInstrumentView];;
  892. }
  893. else { // 消息中心
  894. NoticeMessageViewController *ctrl = [[NoticeMessageViewController alloc] init];
  895. [self.navigationController pushViewController:ctrl animated:YES];
  896. }
  897. }
  898. - (void)showInstrumentView {
  899. SubjectChooseViewController *ctrl = [[SubjectChooseViewController alloc] init];
  900. MJWeakSelf;
  901. [ctrl chooseSubjectCallback:^{
  902. [weakSelf requestUserInfo];
  903. }];
  904. [self.navigationController pushViewController:ctrl animated:YES];
  905. }
  906. #pragma mark ------ WMPlayer
  907. - (void)playVideoWithUrl:(NSString *)fileUrl {
  908. fileUrl = [fileUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  909. _playerFrame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  910. _wmPlayer = [[WMPlayer alloc] initWithFrame:_playerFrame];
  911. WMPlayerModel *playModel = [[WMPlayerModel alloc] init];
  912. playModel.videoURL = [NSURL URLWithString:fileUrl];
  913. _wmPlayer.playerModel = playModel;
  914. _wmPlayer.delegate = self;
  915. _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
  916. _bgView.backgroundColor = [UIColor blackColor];
  917. [[UIApplication sharedApplication].keyWindow addSubview:_bgView];
  918. [[UIApplication sharedApplication].keyWindow addSubview:_wmPlayer];
  919. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:_wmPlayer];
  920. [_wmPlayer play];
  921. }
  922. - (void)wmplayer:(WMPlayer *)wmplayer clickedCloseButton:(UIButton *)backBtn {
  923. [wmplayer removePlayer];
  924. [_bgView removeFromSuperview];
  925. [self setNeedsStatusBarAppearanceUpdate];
  926. }
  927. - (void)wmplayer:(WMPlayer *)wmplayer clickedFullScreenButton:(UIButton *)fullScreenBtn {
  928. self.isRatation = !self.isRatation;
  929. if (self.isRatation) {
  930. [wmplayer removeFromSuperview];
  931. [UIView animateWithDuration:1.0f animations:^{
  932. wmplayer.transform = CGAffineTransformMakeRotation(M_PI_2);
  933. } completion:^(BOOL finished) {
  934. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  935. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  936. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  937. }];
  938. }
  939. else {
  940. [wmplayer removeFromSuperview];
  941. [UIView animateWithDuration:1.0f animations:^{
  942. // 复原
  943. wmplayer.transform = CGAffineTransformIdentity;
  944. } completion:^(BOOL finished) {
  945. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  946. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  947. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  948. }];
  949. }
  950. }
  951. - (void)dealloc {
  952. [[NSNotificationCenter defaultCenter] removeObserver:self];
  953. }
  954. /*
  955. #pragma mark - Navigation
  956. // In a storyboard-based application, you will often want to do a little preparation before navigation
  957. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  958. // Get the new view controller using [segue destinationViewController].
  959. // Pass the selected object to the new view controller.
  960. }
  961. */
  962. @end