澎湃iPad上线版本

topicBannerCollectCell.m 5.5KB

    // // topicBannerCollectCell.m // ThePaperBase // // Created by liyuan on 15/10/28. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "topicBannerCollectCell.h" #import "topicListCell.h" #import "customFlowLayout.h" @interface topicBannerCollectCell()<UICollectionViewDataSource,UICollectionViewDelegate> @property(nonatomic, strong)UICollectionView *collectView; @end @implementation topicBannerCollectCell @synthesize dataList = _dataList; @synthesize delegate; static NSString * const paperCollectReuseIdentifier = @"topicListCell"; - (void)awakeFromNib { // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.backgroundColor = [UIColor clearColor]; self.selectionStyle = UITableViewCellSelectionStyleNone; [self.contentView addSubview:self.collectView]; [self.collectView setCollectionViewLayout:[self VericalLayout]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarOrientationChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; } return self; } - (UICollectionView*)collectView { if (!_collectView) { _collectView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:[self VericalLayout]]; [_collectView registerClass:[topicListCell 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; } #pragma mark -- set data -(void)setDataList:(NSMutableArray *)list{ _dataList = list; [self.collectView reloadData]; } #pragma mark - collect Item - (CGSize)horizonSize { CGFloat width = (CGRectGetWidth(self.bounds)-12)/2; CGFloat viewScale = width/300; CGSize itemSize = CGSizeMake(width , 215*viewScale); return itemSize; } - (CGSize)vericalSize { CGFloat width = (1300/2-12)/2; CGFloat viewScale = width/300; CGSize itemSize = CGSizeMake(width, 215*viewScale); return itemSize; } - (customFlowLayout*)HorizontalLayout { CGFloat width = (CGRectGetWidth(self.bounds)-12)/2; CGFloat viewScale = width/300; CGSize itemSize = CGSizeMake(width , 215*viewScale); customFlowLayout *layout= [[customFlowLayout alloc]init]; layout.scrollDirection = UICollectionViewScrollDirectionVertical; layout.minimumLineSpacing = 12; layout.minimumInteritemSpacing = 12; layout.itemSize = itemSize; return layout; } - (customFlowLayout*)VericalLayout { CGFloat width = (1300/2-12)/2; CGFloat viewScale = width/300; CGSize itemSize = CGSizeMake(width, 215*viewScale); customFlowLayout *layout= [[customFlowLayout alloc]init]; layout.scrollDirection = UICollectionViewScrollDirectionVertical; layout.minimumLineSpacing = 12; layout.minimumInteritemSpacing = 12; layout.itemSize = itemSize; return layout; } #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 { topicListCell *cell = (topicListCell*)[collection dequeueReusableCellWithReuseIdentifier:paperCollectReuseIdentifier forIndexPath:indexPath]; TopicInfoBO *topic = self.dataList[indexPath.row]; cell.topicBO = topic; 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 { if ([self.delegate respondsToSelector:@selector(gotoTopicInfo:)]) { [self.delegate gotoTopicInfo:self.dataList[indexPath.row]]; } } -(void)layoutSubviews{ [super layoutSubviews]; // self.collectView.frame = CGRectMake(0, 0, 1300/2, CGRectGetHeight(self.bounds)); [self setLayout]; } - (void)statusBarOrientationChange:(NSNotification *)notification{ [self setLayout]; } -(void) setLayout{ UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationLandscapeRight || orientation ==UIInterfaceOrientationLandscapeLeft) { self.collectView.frame = CGRectMake(190, 0, 1300/2, CGRectGetHeight(self.bounds)); }else { self.collectView.frame = CGRectMake(90, 0, 1300/2, CGRectGetHeight(self.bounds)); } } @end