|
//
// topicCollectionCoverFlowCell.m
// ThePaperBase
//
// Created by Huixin on 15/10/14.
// Copyright © 2015年 scar1900. All rights reserved.
//
#import "topicCollectionCoverFlowCell.h"
#import "TPImageBaseView.h"
#import "iCarousel.h"
#import "AsyncImageView.h"
#import "UIImage+ImageEffects.h"
#import "UIImage-Extensions.h"
#import "UIImage+wiRoundedRectImage.h"
#import "StyledPageControl.h"
#define IMAGE_SIZE_HEIGHT 125*(rect_screen.size.width)/300
@interface topicCollectionCoverFlowCell()<iCarouselDataSource,iCarouselDelegate>
@property(nonatomic, strong)iCarousel *coverFLow;
@property(nonatomic, strong)NSMutableArray *dataList;
@property(nonatomic, strong)StyledPageControl *pageControl; //页码指示器
@property(nonatomic, strong)NSTimer *timer;
@end
@implementation topicCollectionCoverFlowCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.orientation = [[UIApplication sharedApplication] statusBarOrientation];
self.clipsToBounds = YES;
[self addSubview:self.coverFLow];
[self addSubview:self.pageControl];
[self layoutSubViews];
}
return self;
}
- (void)showNextItem:(NSTimer*)timer {
[self.coverFLow scrollToItemAtIndex:self.coverFLow.currentItemIndex+1 animated:YES];
}
- (void)setSpecialBOList:(NSArray *)specialBOList {
_specialBOList = specialBOList; //bug5498: 问吧合集:问吧精选页上的问吧合集需要实时刷新
if (_specialBOList.count > 0) {
NSMutableArray *tempList = [NSMutableArray array];
[_specialBOList enumerateObjectsUsingBlock:^(NSDictionary *dic, NSUInteger idx, BOOL *stop) {
specialObjectBO *specialBO = setJsonDicToDataModel(dic, [specialObjectBO class]);
[tempList addObject:specialBO];
}];
self.dataList = tempList;
}
}
- (void)setDataList:(NSMutableArray *)dataList {
_dataList = dataList;
if (dataList.count == 1) {
self.coverFLow.autoscroll = 0;
self.coverFLow.scrollEnabled = NO;
}
self.pageControl.numberOfPages = dataList.count;
[self.coverFLow reloadData];
self.coverFLow.currentItemIndex = 0;
self.pageControl.currentPage = 0;
[self layoutSubViews];
[self resetTimer];
}
- (iCarousel*)coverFLow {
if (!_coverFLow) {
_coverFLow = [[iCarousel alloc]initWithFrame:CGRectZero];
_coverFLow.type = iCarouselTypeLinear;
_coverFLow.delegate = self;
_coverFLow.dataSource = self;
_coverFLow.clipsToBounds = YES;
_coverFLow.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
_coverFLow.pagingEnabled = YES;
}
return _coverFLow;
}
- (StyledPageControl *)pageControl {
if (!_pageControl) {
_pageControl = [[StyledPageControl alloc] initWithFrame:CGRectZero];
//_pageControl.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
_pageControl.pageControlStyle = PageControlStyleThumb;
_pageControl.userInteractionEnabled = NO;
_pageControl.hidesForSinglePage = YES;
_pageControl.currentPage = self.coverFLow.currentItemIndex;
//_pageControl.coreSelectedColor = [UIColor colorWithHexString:BLUECOLOR];
//_pageControl.coreNormalColor = [UIColor colorWithHexString:@"0xc5c5c5"];
//_pageControl.strokeWidth = 5;
_pageControl.gapWidth = 8;
//_pageControl.diameter = 13;
_pageControl.backgroundColor = [UIColor clearColor];
_pageControl.thumbImage = Image(@"other/dot.png");
_pageControl.selectedThumbImage = Image(@"other/dot_s.png");
}
return _pageControl;
}
- (void)layoutSubViews {
[self.coverFLow remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.left);
make.top.equalTo(self.top);
make.width.equalTo(self.width);
make.height.mas_equalTo(IMAGE_SIZE_HEIGHT+10);
}];
[self.pageControl remakeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.centerX);
make.top.equalTo(self.bottom).offset(-25);
make.width.mas_equalTo(100);
make.height.mas_equalTo(10);
}];
}
- (void)dealloc {
self.coverFLow.delegate = nil;
self.coverFLow.dataSource = nil;
[self.timer invalidate];
self.timer = nil;
}
#pragma mark - iCarousel dataSource and delegate
- (NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel {
return self.dataList.count;
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view {
if (view == nil) {
view = [[TPImageBaseView alloc] initWithFrame:CGRectMake(0, 0, rect_screen.size.width, IMAGE_SIZE_HEIGHT+10)];
[(TPImageBaseView*)view setType:BASEIMAGETYPESIMPLEIMAGE];
}
TPImageBaseView *item = (TPImageBaseView *)view;
specialObjectBO *contentBO = self.dataList[index];
item.specialBO = contentBO;
return view;
}
- (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index {
if (index != carousel.currentItemIndex) {
return;
}
[MobClick event:@"87"];
specialObjectBO *contentBO = self.dataList[index];
if ([self.delegate respondsToSelector:@selector(pushToCoverFlowDetail:)]) {
[self.delegate pushToCoverFlowDetail:contentBO];
}
}
- (void)carouselCurrentItemIndexDidChange:(iCarousel *)carousel {
self.pageControl.currentPage = carousel.currentItemIndex;
}
- (CGFloat)carousel:(__unused iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
//customize carousel display
switch (option)
{
case iCarouselOptionWrap:
{
//normally you would hard-code this to YES or NO
return YES;
}
case iCarouselOptionSpacing:
{
//add a bit of spacing between the item views
if (self.orientation == UIInterfaceOrientationPortrait
|| self.orientation == UIInterfaceOrientationPortraitUpsideDown) {
return value*1.01f;
}else {
return value*1.01f;
}
}
case iCarouselOptionFadeMax:
{
return value;
}
// case iCarouselOptionShowBackfaces:
case iCarouselOptionRadius:
{
return value;
}
// case iCarouselOptionAngle:
// case iCarouselOptionArc:
// case iCarouselOptionTilt:
// case iCarouselOptionCount:
// case iCarouselOptionFadeMin:
// case iCarouselOptionFadeMinAlpha:
// case iCarouselOptionFadeRange:
// case iCarouselOptionOffsetMultiplier:
// case iCarouselOptionVisibleItems:
default:
{
return value;
}
}
}
- (CGFloat)carouselItemWidth:(iCarousel *)carousel {
return rect_screen.size.width;
}
- (void)carouselDidEndDragging:(iCarousel *)carousel willDecelerate:(BOOL)decelerate {
[self resetTimer];
}
- (void)resetTimer {
if (_timer) {
[self.timer invalidate];
self.timer = nil;
}
_timer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(showNextItem:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSDefaultRunLoopMode];
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
|