动态话题轮播
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
#import "XPMacro.h"
|
#import "XPMacro.h"
|
||||||
#import "NSArray+Safe.h"
|
#import "NSArray+Safe.h"
|
||||||
|
|
||||||
@interface XPPartyHeaderView()<UICollectionViewDelegate, UICollectionViewDataSource>
|
@interface XPPartyHeaderView()<SDCycleScrollViewDelegate>
|
||||||
/// 背景
|
/// 背景
|
||||||
@property (nonatomic, strong) UIView *bgView;
|
@property (nonatomic, strong) UIView *bgView;
|
||||||
/// 轮播图
|
/// 轮播图
|
||||||
|
@@ -10,14 +10,15 @@
|
|||||||
#import <Masonry.h>
|
#import <Masonry.h>
|
||||||
#import "XPMacro.h"
|
#import "XPMacro.h"
|
||||||
#import "NSArray+Safe.h"
|
#import "NSArray+Safe.h"
|
||||||
|
#import <SDCycleScrollView.h>
|
||||||
///View
|
///View
|
||||||
#import "XPMomentTopicHeaderCell.h"
|
#import "XPMomentTopicHeaderCell.h"
|
||||||
|
|
||||||
@interface XPMomentTopicHeaderView()<UICollectionViewDelegate, UICollectionViewDataSource>
|
@interface XPMomentTopicHeaderView()<SDCycleScrollViewDelegate>
|
||||||
/// 背景
|
/// 背景
|
||||||
@property (nonatomic, strong) UIView *bgView;
|
@property (nonatomic, strong) UIView *bgView;
|
||||||
/// 列表
|
/// 轮播图
|
||||||
@property (nonatomic, strong) UICollectionView *collectionView;
|
@property (nonatomic, strong) SDCycleScrollView *cycleScrollView;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@
|
|||||||
#pragma mark - Private Method
|
#pragma mark - Private Method
|
||||||
- (void)initSubViews {
|
- (void)initSubViews {
|
||||||
[self addSubview:self.bgView];
|
[self addSubview:self.bgView];
|
||||||
[self.bgView addSubview:self.collectionView];
|
[self.bgView addSubview:self.cycleScrollView];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)initSubViewConstraints {
|
- (void)initSubViewConstraints {
|
||||||
@@ -45,7 +46,7 @@
|
|||||||
make.right.mas_equalTo(-15);
|
make.right.mas_equalTo(-15);
|
||||||
make.bottom.mas_equalTo(-10);
|
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);
|
make.top.left.right.bottom.mas_equalTo(0);
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
@@ -56,6 +57,23 @@
|
|||||||
return height+20;
|
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
|
#pragma mark - UICollectionViewDelegate
|
||||||
|
|
||||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
||||||
@@ -80,7 +98,12 @@
|
|||||||
|
|
||||||
- (void)setTopicList:(NSArray *)topicList {
|
- (void)setTopicList:(NSArray *)topicList {
|
||||||
_topicList = 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 {
|
- (UIView *)bgView {
|
||||||
@@ -93,25 +116,18 @@
|
|||||||
return _bgView;
|
return _bgView;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UICollectionView *)collectionView {
|
- (SDCycleScrollView *)cycleScrollView {
|
||||||
if (!_collectionView) {
|
if (!_cycleScrollView) {
|
||||||
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
_cycleScrollView = [[SDCycleScrollView alloc] init];
|
||||||
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
_cycleScrollView.backgroundColor = [UIColor clearColor];
|
||||||
CGFloat width = KScreenWidth-15*2;
|
_cycleScrollView.layer.cornerRadius = 10;
|
||||||
CGFloat height = 74.0/345.0*width;
|
_cycleScrollView.layer.masksToBounds = YES;
|
||||||
layout.itemSize = CGSizeMake(width, height);
|
_cycleScrollView.delegate = self;
|
||||||
layout.minimumLineSpacing = 0;
|
_cycleScrollView.showPageControl = NO;
|
||||||
layout.minimumInteritemSpacing = 0;
|
_cycleScrollView.autoScrollTimeInterval = 3.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])];
|
|
||||||
}
|
}
|
||||||
return _collectionView;
|
return _cycleScrollView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Reference in New Issue
Block a user