Skip to content

规范协议名大写,修复timer问题,项目里只留一份文件便于维护 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 0 additions & 53 deletions WCScrollLabelView.h

This file was deleted.

182 changes: 0 additions & 182 deletions WCScrollLabelView.m

This file was deleted.

4 changes: 2 additions & 2 deletions WCScrollLabelViewDemo/WCScrollLabelViewDemo/Classes/WCScrollLabelView.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <UIKit/UIKit.h>
@class WCScrollLabelView;
@protocol scrollLabelViewDelegate <NSObject>
@protocol WCScrollLabelViewDelegate <NSObject>

- (void)scrollLabelView:(WCScrollLabelView *)scrollLabelView didClickAtIndex:(NSInteger)index;

Expand All @@ -18,7 +18,7 @@
/**
代理
*/
@property (nonatomic, weak) id<scrollLabelViewDelegate> delegate;
@property (nonatomic, weak) id<WCScrollLabelViewDelegate> delegate;
/**
标题数组
*/
Expand Down
53 changes: 42 additions & 11 deletions WCScrollLabelViewDemo/WCScrollLabelViewDemo/Classes/WCScrollLabelView.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,36 @@ @interface WCScrollLabelView ()
@end

@implementation WCScrollLabelView
- (instancetype)init
{
self = [super init];
if (self) {
[self setupSubviews];
}
return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_currentIndex = 0;
_stayInterval = 2;
_animationDuration = 0.5;
_contentInsets = UIEdgeInsetsMake(0, 5, 0, 5);
[self addSubview:self.container];
[self.container addSubview:self.currentLabel];
[self.container addSubview:self.willShowLabel];
[self setTapGesture];
[self setupSubviews];
}
return self;
}

- (void)setupSubviews
{
_currentIndex = 0;
_stayInterval = 2;
_animationDuration = 0.5;
_contentInsets = UIEdgeInsetsMake(0, 5, 0, 5);
[self addSubview:self.container];
[self.container addSubview:self.currentLabel];
[self.container addSubview:self.willShowLabel];
[self setTapGesture];
}

- (void)layoutSubviews{
[super layoutSubviews];

Expand All @@ -69,15 +83,24 @@ - (void)layoutSubviews{
- (void)beginScrolling
{
if (self.titleArray.count<2) {
if (self.titleArray.count) {
self.currentLabel.text = [self.titleArray firstObject];
}
return;
}

_currentIndex = 0;
[self creatTimer];
}
- (void)creatTimer
{
_timer = [NSTimer scheduledTimerWithTimeInterval:self.stayInterval target:self selector:@selector(startTimer) userInfo:nil repeats:YES];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:_timer forMode:NSRunLoopCommonModes];
if (nil == _timer) {
_timer = [NSTimer scheduledTimerWithTimeInterval:self.stayInterval target:self selector:@selector(startTimer) userInfo:nil repeats:YES];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:_timer forMode:NSRunLoopCommonModes];
}


}
- (void)startTimer
{
Expand Down Expand Up @@ -179,4 +202,12 @@ - (UILabel *)willShowLabel{
return _willShowLabel;
}

- (void)dealloc
{
if (_timer) {
[_timer invalidate];
_timer = nil;
}
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "ViewController.h"
#import "WCScrollLabelView.h"
@interface ViewController ()<scrollLabelViewDelegate>
@interface ViewController ()<WCScrollLabelViewDelegate>
{
WCScrollLabelView *scrollLabelView;
}
Expand Down