123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- //
- // ShowPhotosViewController.m
- // LN_School
- //
- // Created by 张嵘 on 2019/7/28.
- // Copyright © 2019 Danson. All rights reserved.
- //
- #import "ShowPhotoesViewController.h"
- #import "ShowPhotoesViewModel.h"
- #import <IDMPhotoBrowser/IDMPhotoBrowser.h>
- #import "ShowPhotoesModel.h"
- @interface ShowPhotoesViewController ()
- @property (nonatomic, readwrite, strong) HDCollectionView *collectionView;
- @property (nonatomic, readwrite, strong) ShowPhotoesViewModel *showPhotoesViewModel;
- @property (nonatomic, readwrite, strong) NSMutableArray *dataSourceArr;
- @end
- @implementation ShowPhotoesViewController
- #pragma mark - Life Cycle
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self initUI];
-
- }
- #pragma mark - Private Functions
- - (void)initUI {
- self.title = @"查看照片";
- self.view.backgroundColor = KBackGroundColor;
- [self goBackByNavigation];
-
- [self.view addSubview:self.collectionView];
- [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.view.hd_mas_left);
- make.right.mas_equalTo(self.view.hd_mas_right);
- make.bottom.mas_equalTo(self.view.hd_mas_bottom);
- make.top.mas_equalTo(self.view.hd_mas_top);
- }];
-
- /// 初始化数据
- __weak typeof(self) weakS = self;
-
- _collectionView.collectionV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- [self.showPhotoesViewModel loadData:^(BOOL success, id _Nonnull res) {
- [_collectionView.collectionV.mj_header endRefreshing];
- NSMutableArray *resArr = res;
- HDSectionModel *secModel = resArr.firstObject;
- if (success) {
- [secModel.sectionDataArr.rac_sequence.signal subscribeNext:^(HDCellModel * _Nullable cellModel) {
- if ([cellModel.orgData isKindOfClass:[ShowPhotoesModel class]]) {
- ShowPhotoesModel *showPhotoesModel = cellModel.orgData;
- [self.dataSourceArr addObject:showPhotoesModel.url];
- }
- }];
- [_collectionView hd_setAllDataArr:res];
- }else{
- //error
- }
- }];
- }];
-
- _collectionView.collectionV.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
- [self.showPhotoesViewModel loadData:^(BOOL success, id _Nonnull res) {
- [_collectionView.collectionV.mj_footer endRefreshing];
- NSMutableArray *resArr = res;
- HDSectionModel *secModel = resArr.firstObject;
- if (success) {
- [secModel.sectionDataArr.rac_sequence.signal subscribeNext:^(HDCellModel * _Nullable cellModel) {
- if ([cellModel.orgData isKindOfClass:[ShowPhotoesModel class]]) {
- ShowPhotoesModel *showPhotoesModel = cellModel.orgData;
- [self.dataSourceArr addObject:showPhotoesModel.url];
- }
- }];
- [_collectionView hd_setAllDataArr:res];
- }else{
- //error
- }
- }];
- }];
- [_collectionView.collectionV.mj_header beginRefreshing];
- [_collectionView hd_setAllEventCallBack:^(id backModel, HDCallBackType type) {
- if (type == HDCellCallBack) {
- [weakS clickCell:backModel];
- }else if (type == HDSectionHeaderCallBack){
- [weakS clickHeader:backModel];
- }
- }];
- }
- - (void)clickCell:(HDCellModel*)cellM {
- NSLog(@"点击了%zd--%zd cell",cellM.indexP.section,cellM.indexP.item);
- IDMPhotoBrowser *brower = [[IDMPhotoBrowser alloc] initWithPhotoURLs:self.dataSourceArr animatedFromView:self.view];
- [brower setInitialPageIndex:cellM.indexP.item];
- [self.navigationController presentViewController:brower animated:YES completion:nil];
- }
- - (void)clickHeader:(HDSectionModel*)secM {
- NSLog(@"点击了段头");
- }
- #pragma mark - Lazy Load
- - (HDCollectionView *)collectionView {
- if (!_collectionView) {
- _collectionView = [HDCollectionView hd_makeHDCollectionView:^(HDCollectionViewMaker *maker) {
- maker
- .hd_isNeedTopStop(YES)
- .hd_scrollDirection(UICollectionViewScrollDirectionVertical);
- }];
- _collectionView.backgroundColor = RQBackGroundColor;
- }
- return _collectionView;
- }
- - (ShowPhotoesViewModel *)showPhotoesViewModel {
- if (!_showPhotoesViewModel) {
- _showPhotoesViewModel = [[ShowPhotoesViewModel alloc] init];
- }
- return _showPhotoesViewModel;
- }
- - (NSMutableArray *)dataSourceArr {
- if (!_dataSourceArr) {
- _dataSourceArr = @[].mutableCopy;
- }
- return _dataSourceArr;
- }
- @end
|