Commit 16252f9d authored by admin's avatar admin

修改轮播图 添加点击事件

parent 3a46e680
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "blue-trilateral_down@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "blue-trilateral_down@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "grey-trilateral_right@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "grey-trilateral_right@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "medal_red@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "medal_red@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "medal_orange@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "medal_orange@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "medal_blue@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "medal_blue@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -46,6 +46,19 @@
// #666666
#define kHomeItemTextColor [UIColor colorWithRed:102 / 255.0 green:102 / 255.0 blue:102 / 255.0 alpha:1.0]
// RankingList
// #999999
#define kRankHeadTitleTextColor [UIColor colorWithRed:153 / 255.0 green:153 / 255.0 blue:153 / 255.0 alpha:1.0]
// #006fbc
#define kDateButtonTextColor [UIColor colorWithRed:0 / 255.0 green:111 / 255.0 blue:188 / 255.0 alpha:1.0]
#define kShopCountTextColor [UIColor colorWithRed:255 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:1.0]
// #006fbc
#define kScoreTextColor [UIColor colorWithRed:0 / 255.0 green:111 / 255.0 blue:188 / 255.0 alpha:1.0]
// #444444
#define kShopNameTextColor [UIColor colorWithRed:68 / 255.0 green:68 / 255.0 blue:68 / 255.0 alpha:1.0]
// #fe6903
#define kGradeNumberTextColor [UIColor colorWithRed:254 / 255.0 green:105 / 255.0 blue:3 / 255.0 alpha:1.0]
#import "UIView+Extension.h"
#endif /* Constant_h */
......@@ -25,4 +25,5 @@ typedef enum ScoreState : NSUInteger {
@property (nonatomic, strong) UILabel *someoneLabel; // 发表评语的人
@property (nonatomic, strong) UILabel *dateLabel; // 发表时间
@property (nonatomic, strong) UILabel *remarkLabel; // 评语
@property (nonatomic, strong) UIImageView *arrowImageView;
@end
......@@ -7,16 +7,14 @@
//
#import "HomeHeaderView.h"
#define kCount 5
#define ImageCount 5
@interface HomeHeaderView () <UIScrollViewDelegate>
{
UIImageView *_centerView;
UIImageView *_reusableView;
}
@property (nonatomic,assign) BOOL isDragging; //是否正在拖动
@property (nonatomic,strong) NSTimer *timer; //设置动画
@end
@implementation HomeHeaderView
......@@ -36,34 +34,29 @@
#pragma mark - Private Methods
- (void)setup
{
_isDragging = NO;
// 天气label
self.weatherLabel.text = @"上海 ⛅️ 多云转晴 21-29℃";
// 设置代理
self.scrollView.delegate = self;
CGFloat w = _scrollView.frame.size.width;
CGFloat h = _scrollView.frame.size.height;
_scrollView.pagingEnabled = YES;
_scrollView.contentSize = CGSizeMake(w * 3, 0);
_scrollView.contentOffset = CGPointMake(w, 0);
_scrollView.showsHorizontalScrollIndicator = NO;
CGFloat width = self.scrollView.frame.size.width;
CGFloat height = self.scrollView.frame.size.height;
_scrollView.contentSize = CGSizeMake(ImageCount * width, 0);
_centerView = [[UIImageView alloc] init];
_centerView.image = [UIImage imageNamed:@"00.jpg"];
_centerView.frame = CGRectMake(w, 0, w, h);
_centerView.tag = 0;
_centerView.userInteractionEnabled = YES;
[_scrollView addSubview:_centerView];
for (int i = 0; i < ImageCount; i++) {
UIImageView *imageView = [[UIImageView alloc] init];
CGFloat imageX = i * width;
CGFloat imageY = 0.f;
imageView.frame = CGRectMake(imageX, imageY, width, height);
imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"0%d", i]];
imageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGRClick:)];
[imageView addGestureRecognizer:tapGR];
[_scrollView addSubview:imageView];
}
// 添加点击事件
UITapGestureRecognizer *tapCenterGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGRClick:)];
[_centerView addGestureRecognizer:tapCenterGR];
_reusableView = [[UIImageView alloc] init];
_reusableView.frame = _scrollView.bounds;
UITapGestureRecognizer *tapReusableGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGRClick:)];
[_reusableView addGestureRecognizer:tapReusableGR];
// 设置时钟动画 定时器
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.5f target:self selector:@selector(update:) userInfo:nil repeats:YES];
......@@ -78,12 +71,16 @@
return ;
}
CGPoint offSet = self.scrollView.contentOffset;
offSet.x +=offSet.x;
if (offSet.x == 0) {
offSet.x = _scrollView.frame.size.width;
} else if (offSet.x <= (ImageCount - 2) * _scrollView.frame.size.width){
offSet.x +=_scrollView.frame.size.width;
} else {
offSet.x = 0;
}
[self.scrollView setContentOffset:offSet animated:YES];
if (offSet.x >= self.frame.size.width *2) {
offSet.x = self.frame.size.width;
}
}
- (void)tapGRClick:(UITapGestureRecognizer *)sender
......@@ -95,44 +92,7 @@
#pragma mark - UIScrollView Delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offsetX = scrollView.contentOffset.x;
CGFloat w = scrollView.frame.size.width;
// 1.设置 循环利用view 的位置
CGRect f = _reusableView.frame;
NSInteger index = 0;
if (offsetX > _centerView.frame.origin.x) { // 显示在最右边
f.origin.x = scrollView.contentSize.width - w;
index = _centerView.tag + 1;
if (index >= kCount) index = 0;
} else { // 显示在最左边
f.origin.x = 0;
index = _centerView.tag - 1;
if (index < 0) index = kCount - 1;
}
_reusableView.frame = f;
_reusableView.tag = index;
NSString *icon = [NSString stringWithFormat:@"0%ld.jpg", (long)index];
_reusableView.image = [UIImage imageNamed:icon];
// 2.显示了 最左 或者 最右 的图片
if (offsetX <= 0 || offsetX >= w * 2) {
// 2.1.交换 中间的 和 循环利用的
UIImageView *temp = _centerView;
_centerView = _reusableView;
_reusableView = temp;
// 2.2.设置显示位置
_centerView.frame = _reusableView.frame;
scrollView.contentOffset = CGPointMake(w, 0);
[_reusableView removeFromSuperview];
} else {
[_scrollView addSubview:_reusableView];
}
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
......@@ -152,6 +112,7 @@
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
_scrollView.bounces = NO;
_scrollView.pagingEnabled = YES;
_scrollView.delegate = self;
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.showsVerticalScrollIndicator = NO;
[self addSubview:_scrollView];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment