小说绘上架版本
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// WXYZ_AnnouncementView.h
|
||||
// GKADRollingView
|
||||
//
|
||||
// Created by Gao on 2017/2/16.
|
||||
// Copyright © 2017年 gao. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "WXYZ_AnnouncementViewCollectionViewCell.h"
|
||||
|
||||
@interface WXYZ_AnnouncementView : UIView
|
||||
|
||||
typedef void(^WXYZ_AnnouncementViewTapBlock) (NSString *path, NSUInteger index);
|
||||
|
||||
@property (nonatomic, copy) WXYZ_AnnouncementViewTapBlock clickAdBlock;
|
||||
|
||||
@property (nonatomic, strong) NSArray<TFAnnouncementModel *> *modelArr;
|
||||
|
||||
@property (nonatomic, strong) UIColor *titleColor; // default is orange
|
||||
|
||||
@property (nonatomic, strong) UIFont *textFont; // default is 12
|
||||
|
||||
@property (nonatomic, strong) UIColor *textColor; // default is black
|
||||
|
||||
@property (nonatomic, assign) NSTimeInterval duration; // default is 3s
|
||||
|
||||
/// 是否居中,默认靠左
|
||||
@property (nonatomic, assign) BOOL isCenter;
|
||||
|
||||
@end
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
//
|
||||
// WXYZ_AnnouncementView.m
|
||||
// GKADRollingView
|
||||
//
|
||||
// Created by Gao on 2017/2/16.
|
||||
// Copyright © 2017年 gao. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_AnnouncementView.h"
|
||||
|
||||
@interface WXYZ_AnnouncementView () <UICollectionViewDelegate,UICollectionViewDataSource>
|
||||
{
|
||||
NSTimer *_timer;
|
||||
UICollectionView *_collectionView;
|
||||
}
|
||||
|
||||
@property (nonatomic, assign) NSInteger visibleItems;
|
||||
|
||||
@end
|
||||
|
||||
@implementation WXYZ_AnnouncementView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
[self createSubviews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
||||
layout.minimumLineSpacing = 0;
|
||||
layout.minimumInteritemSpacing = 0;
|
||||
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
||||
layout.itemSize = CGSizeMake(SCREEN_WIDTH - 2 * kMargin, kLabelHeight);
|
||||
|
||||
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) collectionViewLayout:layout];
|
||||
_collectionView.showsVerticalScrollIndicator = NO;
|
||||
_collectionView.pagingEnabled = YES;
|
||||
_collectionView.scrollEnabled = NO;
|
||||
_collectionView.delegate = self;
|
||||
_collectionView.dataSource = self;
|
||||
_collectionView.backgroundColor = [UIColor clearColor];
|
||||
[self addSubview:_collectionView];
|
||||
[_collectionView registerClass:[WXYZ_AnnouncementViewCollectionViewCell class] forCellWithReuseIdentifier:@"WXYZ_AnnouncementViewCollectionViewCell"];
|
||||
|
||||
[_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.mas_equalTo(self);
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
- (void)setModelArr:(NSArray<TFAnnouncementModel *> *)modelArr
|
||||
{
|
||||
if (_modelArr != modelArr) {
|
||||
_modelArr = modelArr;
|
||||
[_collectionView reloadData];
|
||||
|
||||
if (_timer == nil) {
|
||||
_timer = [NSTimer timerWithTimeInterval:_duration?:5 target:self selector:@selector(nextPage) userInfo:nil repeats:YES];
|
||||
NSRunLoop *runloop = [NSRunLoop currentRunLoop];
|
||||
[runloop addTimer:_timer forMode:NSRunLoopCommonModes];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)starTimer
|
||||
{
|
||||
//开启定时器
|
||||
[_timer setFireDate:[NSDate distantPast]];
|
||||
}
|
||||
|
||||
- (void)stopTimer
|
||||
{
|
||||
//暂停定时器
|
||||
[_timer setFireDate:[NSDate distantFuture]];
|
||||
}
|
||||
|
||||
- (void)nextPage
|
||||
{
|
||||
@try {
|
||||
if (self.visibleItems == _modelArr.count) {
|
||||
self.visibleItems = 0;
|
||||
[self->_collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:self.visibleItems inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:NO];
|
||||
}
|
||||
self.visibleItems++;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (self.visibleItems < _modelArr.count) {
|
||||
[self->_collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:self.visibleItems inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:YES];
|
||||
}
|
||||
});
|
||||
} @catch (NSException *exception) {
|
||||
|
||||
} @finally {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
||||
{
|
||||
return _modelArr.count + 1;
|
||||
}
|
||||
|
||||
- (WXYZ_AnnouncementViewCollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
WXYZ_AnnouncementViewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WXYZ_AnnouncementViewCollectionViewCell" forIndexPath:indexPath];
|
||||
cell.textColor = self.textColor;
|
||||
cell.isCenter = self.isCenter;
|
||||
if (indexPath.row == 0) {
|
||||
cell.announcementModel = _modelArr.lastObject;
|
||||
} else {
|
||||
if (indexPath.row - 1 >= 0 && indexPath.row - 1 < _modelArr.count) {
|
||||
cell.announcementModel = _modelArr[indexPath.row - 1];
|
||||
} else {
|
||||
cell.announcementModel = _modelArr.firstObject;
|
||||
}
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
if (indexPath.row == 0) {
|
||||
self.clickAdBlock(_modelArr.lastObject.content, indexPath.row);
|
||||
} else {
|
||||
self.clickAdBlock(_modelArr[indexPath.row - 1].content, indexPath.row - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// WXYZ_AnnouncementViewCollectionViewCell.h
|
||||
// GKADRollingView
|
||||
//
|
||||
// Created by Gao on 2017/2/16.
|
||||
// Copyright © 2017年 gao. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TFBookRackModel.h"
|
||||
|
||||
@interface WXYZ_AnnouncementViewCollectionViewCell : UICollectionViewCell
|
||||
|
||||
@property (nonatomic, strong) TFAnnouncementModel *announcementModel;
|
||||
|
||||
@property (nonatomic, strong) UIColor *titleColor; // default is orange
|
||||
|
||||
@property (nonatomic, strong) UIFont *textFont; // default is 12
|
||||
|
||||
@property (nonatomic, strong) UIColor *textColor; // default is black
|
||||
|
||||
/// 文字是否居中
|
||||
@property (nonatomic, assign) BOOL isCenter;
|
||||
|
||||
@end
|
||||
Executable
+83
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// WXYZ_AnnouncementViewCollectionViewCell.m
|
||||
// GKADRollingView
|
||||
//
|
||||
// Created by Gao on 2017/2/16.
|
||||
// Copyright © 2017年 gao. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_AnnouncementViewCollectionViewCell.h"
|
||||
|
||||
@interface WXYZ_AnnouncementViewCollectionViewCell ()
|
||||
|
||||
@property (nonatomic, strong) UILabel *titleLabel;
|
||||
|
||||
@property (nonatomic, strong) UIImageView *headerImg;
|
||||
|
||||
@end
|
||||
|
||||
@implementation WXYZ_AnnouncementViewCollectionViewCell
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self createSubviews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
_titleLabel = [[UILabel alloc] init];
|
||||
_titleLabel.font = _textFont?:kFont12;
|
||||
_titleLabel.textColor = _textColor?:[UIColor blackColor];
|
||||
_titleLabel.numberOfLines = 1;
|
||||
[self addSubview:_titleLabel];
|
||||
|
||||
_headerImg = [[UIImageView alloc] init];
|
||||
[_headerImg setImage:[[UIImage imageNamed:@"rack_notice"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
|
||||
_headerImg.tintColor = kMainColor;
|
||||
[self addSubview:_headerImg];
|
||||
|
||||
[_headerImg mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(0);
|
||||
make.top.mas_equalTo(0);
|
||||
make.bottom.mas_equalTo(self.mas_bottom);
|
||||
make.width.mas_equalTo(self.mas_height);
|
||||
}];
|
||||
|
||||
[_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(_headerImg.mas_right).with.offset(kHalfMargin);
|
||||
make.top.mas_equalTo(0);
|
||||
make.bottom.mas_equalTo(self.mas_bottom);
|
||||
#if TF_Sign_Mode
|
||||
make.right.mas_equalTo(self.mas_right).with.offset(- kHalfMargin - 100);
|
||||
#else
|
||||
make.right.mas_equalTo(self.mas_right).with.offset(- kHalfMargin);
|
||||
#endif
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
- (void)setAnnouncementModel:(TFAnnouncementModel *)announcementModel
|
||||
{
|
||||
_announcementModel = announcementModel;
|
||||
|
||||
_titleLabel.text = announcementModel.title;
|
||||
}
|
||||
|
||||
- (void)setTextColor:(UIColor *)textColor {
|
||||
_titleLabel.textColor = textColor;
|
||||
}
|
||||
|
||||
- (void)setIsCenter:(BOOL)isCenter {
|
||||
if (isCenter) {
|
||||
[_titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.center.equalTo(self);
|
||||
}];
|
||||
_headerImg.hidden = YES;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user