澎湃iPad上线版本

topicContentListCell.m 6.7KB

    // // topicContentListCell.m // ThePaperHD // // Created by scar1900 on 15/2/16. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "topicContentListCell.h" #import "paperCollectCell.h" #import "customFlowLayout.h" @interface topicContentListCell()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,paperCollectDelegate> @property(nonatomic, strong)UICollectionView *collectView; @property(nonatomic, strong)NSMutableArray *dataList; @end @implementation topicContentListCell @synthesize nodeBO = _nodeBO; @synthesize delegate; static NSString * const paperCollectReuseIdentifier = @"frontPageCollectItem"; - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // Initialization code self.backgroundColor = [UIColor clearColor]; self.selectionStyle = UITableViewCellSelectionStyleNone; [self addSubview:self.collectView]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarOrientationChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; } return self; } - (void)statusBarOrientationChange:(NSNotification *)notification { [self.collectView setCollectionViewLayout:[self VericalLayout]]; [self layoutSubviews]; } - (UICollectionView*)collectView { if (!_collectView) { _collectView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:[self VericalLayout]]; [_collectView registerClass:[paperCollectCell class] forCellWithReuseIdentifier:paperCollectReuseIdentifier]; _collectView.backgroundColor = [UIColor clearColor]; _collectView.allowsSelection = YES; _collectView.scrollEnabled = NO; _collectView.showsHorizontalScrollIndicator= NO; _collectView.showsVerticalScrollIndicator= NO; _collectView.delaysContentTouches = NO; _collectView.delegate = self; _collectView.dataSource = self; } return _collectView; } - (void)setNodeBO:(nodeObjectBO *)nodeBO { _nodeBO = nodeBO; NSArray *contList = nodeBO.contList; self.dataList = [NSMutableArray array]; [contList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { listContObjectVO *listBO = setJsonDicToDataModel(obj, [listContObjectVO class]); UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationPortrait || orientation ==UIInterfaceOrientationPortraitUpsideDown) { if (idx<4) { [self.dataList addObject:listBO]; } }else { [self.dataList addObject:listBO]; } }]; [self.collectView reloadData]; } #pragma mark - collect Item - (CGSize)horizonSize { CGFloat width = (CGRectGetWidth(self.bounds)-25*2-15)/3; CGFloat viewScale = width/300; CGSize itemSize = CGSizeMake(width , 215*viewScale); return itemSize; } - (CGSize)vericalSize { CGFloat width = (1312/2-35)/2; CGFloat viewScale = width/300; CGSize itemSize = CGSizeMake(width, 215*viewScale); return itemSize; } - (customFlowLayout*)HorizontalLayout { CGFloat width = (CGRectGetWidth(self.bounds)-25*2-15)/3; CGFloat viewScale = width/300; CGSize itemSize = CGSizeMake(width , 215*viewScale); customFlowLayout *layout= [[customFlowLayout alloc]init]; layout.scrollDirection = UICollectionViewScrollDirectionVertical; layout.minimumLineSpacing = 25; layout.minimumInteritemSpacing = 25; layout.itemSize = itemSize; return layout; } - (customFlowLayout*)VericalLayout { CGFloat width = (1312/2-35)/2; CGFloat viewScale = width/300; CGSize itemSize = CGSizeMake(width, 215*viewScale); customFlowLayout *layout= [[customFlowLayout alloc]init]; layout.scrollDirection = UICollectionViewScrollDirectionVertical; layout.minimumLineSpacing = 35; layout.minimumInteritemSpacing = 35; layout.itemSize = itemSize; return layout; } - (void)layoutSubviews { CGFloat padding = 0; UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { padding = 125; } self.collectView.frame = CGRectMake(padding, 0, 1312/2, CGRectGetHeight(self.bounds)); } #pragma mark - parper collect delegate - (void)goToColumnPage:(listContObjectVO*)listBO { if ([self.delegate respondsToSelector:@selector(goToMoreInfoPage:)]) { [self.delegate goToMoreInfoPage:listBO]; } } #pragma mark - collect view delegate and datasource - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.dataList?self.dataList.count:0; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collection cellForItemAtIndexPath:(NSIndexPath *)indexPath { paperCollectCell *cell = (paperCollectCell*)[collection dequeueReusableCellWithReuseIdentifier:paperCollectReuseIdentifier forIndexPath:indexPath]; listContObjectVO* data = self.dataList[indexPath.row]; data.cornerLabelDesc = @""; cell.listContentBO = data; cell.delegate = self; return cell; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return [self vericalSize]; } -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { UIEdgeInsets top = {20,0,20,0}; return top; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { paperCollectCell *cell = (paperCollectCell*)[collectionView cellForItemAtIndexPath:indexPath]; [UIView animateWithDuration:0.25 animations:^{ cell.transform = CGAffineTransformMakeScale(0.95, 0.95); } completion:^(BOOL finished) { cell.transform = CGAffineTransformMakeScale(1.00, 1.00); if ([self.delegate respondsToSelector:@selector(pushToDetailpage:)]) { [self.delegate pushToDetailpage:cell.listContentBO]; } }]; } - (void)awakeFromNib { // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end