动态话题轮播
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
#import "XPMacro.h"
|
||||
#import "NSArray+Safe.h"
|
||||
|
||||
@interface XPPartyHeaderView()<UICollectionViewDelegate, UICollectionViewDataSource>
|
||||
@interface XPPartyHeaderView()<SDCycleScrollViewDelegate>
|
||||
/// 背景
|
||||
@property (nonatomic, strong) UIView *bgView;
|
||||
/// 轮播图
|
||||
|
@@ -10,14 +10,15 @@
|
||||
#import <Masonry.h>
|
||||
#import "XPMacro.h"
|
||||
#import "NSArray+Safe.h"
|
||||
#import <SDCycleScrollView.h>
|
||||
///View
|
||||
#import "XPMomentTopicHeaderCell.h"
|
||||
|
||||
@interface XPMomentTopicHeaderView()<UICollectionViewDelegate, UICollectionViewDataSource>
|
||||
@interface XPMomentTopicHeaderView()<SDCycleScrollViewDelegate>
|
||||
/// 背景
|
||||
@property (nonatomic, strong) UIView *bgView;
|
||||
/// 列表
|
||||
@property (nonatomic, strong) UICollectionView *collectionView;
|
||||
/// 轮播图
|
||||
@property (nonatomic, strong) SDCycleScrollView *cycleScrollView;
|
||||
|
||||
@end
|
||||
|
||||
@@ -35,7 +36,7 @@
|
||||
#pragma mark - Private Method
|
||||
- (void)initSubViews {
|
||||
[self addSubview:self.bgView];
|
||||
[self.bgView addSubview:self.collectionView];
|
||||
[self.bgView addSubview:self.cycleScrollView];
|
||||
}
|
||||
|
||||
- (void)initSubViewConstraints {
|
||||
@@ -45,7 +46,7 @@
|
||||
make.right.mas_equalTo(-15);
|
||||
make.bottom.mas_equalTo(-10);
|
||||
}];
|
||||
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
[self.cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.left.right.bottom.mas_equalTo(0);
|
||||
}];
|
||||
}
|
||||
@@ -56,6 +57,23 @@
|
||||
return height+20;
|
||||
}
|
||||
|
||||
- (Class)customCollectionViewCellClassForCycleScrollView:(SDCycleScrollView *)view {
|
||||
return [XPMomentTopicHeaderCell class];
|
||||
}
|
||||
|
||||
- (void)setupCustomCell:(UICollectionViewCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view {
|
||||
XPMomentTopicHeaderCell *topicCell = (XPMomentTopicHeaderCell *)cell;
|
||||
MonentsTopicModel *model = [self.topicList safeObjectAtIndex1:index];
|
||||
topicCell.topicModel = model;
|
||||
}
|
||||
|
||||
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(momentTopicHeaderViewClickTopic:)]) {
|
||||
MonentsTopicModel *topicModel = [self.topicList safeObjectAtIndex1:index];
|
||||
[self.delegate momentTopicHeaderViewClickTopic:topicModel];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - UICollectionViewDelegate
|
||||
|
||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
||||
@@ -80,7 +98,12 @@
|
||||
|
||||
- (void)setTopicList:(NSArray *)topicList {
|
||||
_topicList = topicList;
|
||||
[self.collectionView reloadData];
|
||||
NSMutableArray *tempArr = [NSMutableArray array];
|
||||
for (int i = 0; i<topicList.count; i++) {
|
||||
[tempArr addObject:@""];
|
||||
}
|
||||
self.cycleScrollView.localizationImageNamesGroup = tempArr;
|
||||
[self.cycleScrollView autoScroll];
|
||||
}
|
||||
|
||||
- (UIView *)bgView {
|
||||
@@ -93,25 +116,18 @@
|
||||
return _bgView;
|
||||
}
|
||||
|
||||
- (UICollectionView *)collectionView {
|
||||
if (!_collectionView) {
|
||||
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
||||
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
||||
CGFloat width = KScreenWidth-15*2;
|
||||
CGFloat height = 74.0/345.0*width;
|
||||
layout.itemSize = CGSizeMake(width, height);
|
||||
layout.minimumLineSpacing = 0;
|
||||
layout.minimumInteritemSpacing = 0;
|
||||
|
||||
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
||||
_collectionView.delegate = self;
|
||||
_collectionView.dataSource = self;
|
||||
_collectionView.pagingEnabled = YES;
|
||||
_collectionView.showsVerticalScrollIndicator = NO;
|
||||
_collectionView.showsHorizontalScrollIndicator = NO;
|
||||
[_collectionView registerClass:[XPMomentTopicHeaderCell class] forCellWithReuseIdentifier:NSStringFromClass([XPMomentTopicHeaderCell class])];
|
||||
- (SDCycleScrollView *)cycleScrollView {
|
||||
if (!_cycleScrollView) {
|
||||
_cycleScrollView = [[SDCycleScrollView alloc] init];
|
||||
_cycleScrollView.backgroundColor = [UIColor clearColor];
|
||||
_cycleScrollView.layer.cornerRadius = 10;
|
||||
_cycleScrollView.layer.masksToBounds = YES;
|
||||
_cycleScrollView.delegate = self;
|
||||
_cycleScrollView.showPageControl = NO;
|
||||
_cycleScrollView.autoScrollTimeInterval = 3.0;
|
||||
}
|
||||
return _collectionView;
|
||||
return _cycleScrollView;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user