From e60bcf487d7aa656a707ffb7fbf6c9bda93cb60a Mon Sep 17 00:00:00 2001 From: mlch911 Date: Mon, 11 Oct 2021 17:06:32 +0800 Subject: [PATCH 1/6] Add Support for AutoLayout --- DPScrollNumberLabel/DPScrollNumberLabel.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/DPScrollNumberLabel/DPScrollNumberLabel.m b/DPScrollNumberLabel/DPScrollNumberLabel.m index 4c7de89..34758f5 100644 --- a/DPScrollNumberLabel/DPScrollNumberLabel.m +++ b/DPScrollNumberLabel/DPScrollNumberLabel.m @@ -193,6 +193,11 @@ - (void)initSign { } } +- (CGSize)intrinsicContentSize { + return CGSizeMake((MIN(self.rowNumber ?: [self calculateNumberRow:self.currentNumber.integerValue], self.maxRowNumber) + self.signRow) * self.cellWidth, + self.numberCellHeight/numberCellLineCount); +} + #pragma mark - ConfigViews - (void)initParent{ @@ -250,6 +255,7 @@ - (void)updateToRowNumber:(NSInteger)rowNumber { [self updateCellModelToFitRowNumber:rowNumber]; [self updateCellLayoutToFitRowNumber:rowNumber withAnimation:YES]; self.rowNumber = rowNumber; + [self invalidateIntrinsicContentSize]; } - (void)removeAllCellFromSuperview { From b8db25ae7ddc970bac3d01018dee9da7a9c78001 Mon Sep 17 00:00:00 2001 From: mlch911 Date: Mon, 11 Oct 2021 17:06:41 +0800 Subject: [PATCH 2/6] Fix Bug --- DPScrollNumberLabel/DPScrollNumberLabel.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DPScrollNumberLabel/DPScrollNumberLabel.m b/DPScrollNumberLabel/DPScrollNumberLabel.m index 34758f5..e1fc0de 100644 --- a/DPScrollNumberLabel/DPScrollNumberLabel.m +++ b/DPScrollNumberLabel/DPScrollNumberLabel.m @@ -76,6 +76,7 @@ @interface DPScrollNumberLabel() @property (nonatomic, strong) UIFont *font; @property (nonatomic, assign) SignSetting signSetting; @property (nonatomic, assign) NSUInteger signRow; +@property (nonatomic, assign) BOOL fixedRowNumber; @end @@ -120,6 +121,7 @@ - (instancetype)initWithNumber:(NSNumber *)number fontSize:(CGFloat)fontSize tex self.textColor = textColor; self.isAnimating = NO; self.finishedAnimationCount = 0; + self.fixedRowNumber = rowNumber; self.rowNumber = (rowNumber > 0 && rowNumber <= 8) ? rowNumber : 0; self.maxRowNumber = (self.rowNumber == 0) ? 8 : rowNumber; self.signSetting = signSetting; @@ -161,6 +163,7 @@ - (instancetype)initWithNumber:(NSNumber *)number font:(UIFont *)font textColor: self.textColor = textColor; self.isAnimating = NO; self.finishedAnimationCount = 0; + self.fixedRowNumber = rowNumber; self.rowNumber = (rowNumber > 0 && rowNumber <= 8) ? rowNumber : 0; self.maxRowNumber = (self.rowNumber == 0) ? 8 : rowNumber; self.signSetting = signSetting; @@ -248,7 +251,7 @@ - (void)initCells { } - (void)updateToRowNumber:(NSInteger)rowNumber { - if (rowNumber == self.rowNumber) { + if (rowNumber == self.rowNumber || self.fixedRowNumber) { return; } [self removeAllCellFromSuperview]; From 16605c020b4d1ce500f69a163caea5c909154ec6 Mon Sep 17 00:00:00 2001 From: mlch911 Date: Thu, 29 Feb 2024 10:51:56 +0800 Subject: [PATCH 3/6] Public font & textColor --- DPScrollNumberLabel/DPScrollNumberLabel.h | 36 +++++++++++++---------- DPScrollNumberLabel/DPScrollNumberLabel.m | 21 ++++++++++--- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/DPScrollNumberLabel/DPScrollNumberLabel.h b/DPScrollNumberLabel/DPScrollNumberLabel.h index e90f624..91f3d9f 100644 --- a/DPScrollNumberLabel/DPScrollNumberLabel.h +++ b/DPScrollNumberLabel/DPScrollNumberLabel.h @@ -30,7 +30,11 @@ typedef NS_ENUM(NSUInteger, SignSetting) { /** it synchronize with the value you set by method '-changeToNumber:animated:' and '-changeToNumber:interval:animated:' */ -@property (nonatomic, strong, readonly)NSNumber *currentNumber; +@property (nonatomic, strong, readonly) NSNumber *currentNumber; + +@property (nonatomic, strong) UIFont *font; + +@property (nonatomic, strong) UIColor *textColor; /** dynamic init method, the instance created by this method have a dynamic row count, it's row will change with the value you setting @@ -39,7 +43,7 @@ typedef NS_ENUM(NSUInteger, SignSetting) { @param fontSize: the number font size you want @return the instance of DPScrollNumberLabel */ -- (instancetype)initWithNumber:(NSNumber *)number fontSize:(CGFloat)fontSize; +- (nonnull instancetype)initWithNumber:(NSNumber *)number fontSize:(CGFloat)fontSize; /** dynamic init method, the instance created by this method have a dynamic row count, it's row will change with the value you setting @@ -49,7 +53,7 @@ typedef NS_ENUM(NSUInteger, SignSetting) { @param textColor: the number color you want @return the instance of DPScrollNumberLabel */ -- (instancetype)initWithNumber:(NSNumber *)number fontSize:(CGFloat)fontSize textColor:(UIColor *)textColor; +- (nonnull instancetype)initWithNumber:(NSNumber *)number fontSize:(CGFloat)fontSize textColor:(UIColor *)textColor; /** dynamic init method, the instance created by this method have a dynamic row count, it's row will change with the value you setting @@ -59,7 +63,7 @@ typedef NS_ENUM(NSUInteger, SignSetting) { @param signSetting: the sign setting for DPScrollNumberLabel, you have three option: unsigned, normal, signed. see SignSetting enum declaration for detail. @return the instance of DPScrollNumberLabel */ -- (instancetype)initWithNumber:(NSNumber *)number fontSize:(CGFloat)fontSize signSetting:(SignSetting)signSetting; +- (nonnull instancetype)initWithNumber:(NSNumber *)number fontSize:(CGFloat)fontSize signSetting:(SignSetting)signSetting; /** dynamic init method, the instance created by this method have a dynamic row count, it's row will change with the value you setting @@ -70,7 +74,7 @@ typedef NS_ENUM(NSUInteger, SignSetting) { @param signSetting: the sign setting for DPScrollNumberLabel, you have three option: unsigned, normal, signed. see SignSetting enum declaration for detail. @return the instance of DPScrollNumberLabel */ -- (instancetype)initWithNumber:(NSNumber *)number fontSize:(CGFloat)fontSize textColor:(UIColor *)textColor signSetting:(SignSetting)signSetting; +- (nonnull instancetype)initWithNumber:(NSNumber *)number fontSize:(CGFloat)fontSize textColor:(UIColor *)textColor signSetting:(SignSetting)signSetting; /** dynamic init method, the instance created by this method have a dynamic row count, it's row will change with the value you setting @@ -79,7 +83,7 @@ typedef NS_ENUM(NSUInteger, SignSetting) { @param font: the number font you want @return the instance of DPScrollNumberLabel */ -- (instancetype)initWithNumber:(NSNumber *)number font:(UIFont *)font; +- (nonnull instancetype)initWithNumber:(NSNumber *)number font:(UIFont *)font; /** dynamic init method, the instance created by this method have a dynamic row count, it's row will change with the value you setting @@ -89,7 +93,7 @@ typedef NS_ENUM(NSUInteger, SignSetting) { @param textColor: the number color you want @return the instance of DPScrollNumberLabel */ -- (instancetype)initWithNumber:(NSNumber *)number font:(UIFont *)font textColor:(UIColor *)textColor; +- (nonnull instancetype)initWithNumber:(NSNumber *)number font:(UIFont *)font textColor:(UIColor *)textColor; /** dynamic init method, the instance created by this method have a dynamic row count, it's row will change with the value you setting @@ -99,7 +103,7 @@ typedef NS_ENUM(NSUInteger, SignSetting) { @param signSetting: the sign setting for DPScrollNumberLabel, you have three option: unsigned, normal, signed. see SignSetting enum declaration for detail. @return the instance of DPScrollNumberLabel */ -- (instancetype)initWithNumber:(NSNumber *)number font:(UIFont *)font signSetting:(SignSetting)signSetting; +- (nonnull instancetype)initWithNumber:(NSNumber *)number font:(UIFont *)font signSetting:(SignSetting)signSetting; /** dynamic init method, the instance created by this method have a dynamic row count, it's row will change with the value you setting @@ -110,7 +114,7 @@ typedef NS_ENUM(NSUInteger, SignSetting) { @param signSetting: the sign setting for DPScrollNumberLabel, you have three option: unsigned, normal, signed. see SignSetting enum declaration for detail. @return the instance of DPScrollNumberLabel */ -- (instancetype)initWithNumber:(NSNumber *)number font:(UIFont *)font textColor:(UIColor *)textColor signSetting:(SignSetting)signSetting; +- (nonnull instancetype)initWithNumber:(NSNumber *)number font:(UIFont *)font textColor:(UIColor *)textColor signSetting:(SignSetting)signSetting; /*-------------------------------------------- dynamic init method end ------------------------------------------------- @@ -132,7 +136,7 @@ typedef NS_ENUM(NSUInteger, SignSetting) { @param rowNumber: the row count of DPScrollNumberLabel, it means the row count will be changeless @return the instance of DPScrollNumberLabel */ -- (instancetype)initWithNumber:(NSNumber *)number +- (nonnull instancetype)initWithNumber:(NSNumber *)number fontSize:(CGFloat)fontSize rowNumber:(NSUInteger)rowNumber; @@ -146,7 +150,7 @@ typedef NS_ENUM(NSUInteger, SignSetting) { @param rowNumber: the row count of DPScrollNumberLabel, it means the row count will be changeless @return the instance of DPScrollNumberLabel */ -- (instancetype)initWithNumber:(NSNumber *)number +- (nonnull instancetype)initWithNumber:(NSNumber *)number fontSize:(CGFloat)fontSize textColor:(UIColor *)textColor rowNumber:(NSUInteger)rowNumber; @@ -161,7 +165,7 @@ typedef NS_ENUM(NSUInteger, SignSetting) { @param rowNumber: the row count of DPScrollNumberLabel, it means the row count will be changeless @return the instance of DPScrollNumberLabel */ -- (instancetype)initWithNumber:(NSNumber *)number +- (nonnull instancetype)initWithNumber:(NSNumber *)number fontSize:(CGFloat)fontSize signSetting:(SignSetting)signSetting rowNumber:(NSUInteger)rowNumber; @@ -177,7 +181,7 @@ typedef NS_ENUM(NSUInteger, SignSetting) { @param rowNumber: the row count of DPScrollNumberLabel, it means the row count will be changeless @return the instance of DPScrollNumberLabel */ -- (instancetype)initWithNumber:(NSNumber *)number +- (nonnull instancetype)initWithNumber:(NSNumber *)number fontSize:(CGFloat)fontSize textColor:(UIColor *)textColor signSetting:(SignSetting)signSetting @@ -193,7 +197,7 @@ typedef NS_ENUM(NSUInteger, SignSetting) { @param rowNumber: the row count of DPScrollNumberLabel, it means the row count will be changeless @return the instance of DPScrollNumberLabel */ -- (instancetype)initWithNumber:(NSNumber *)number +- (nonnull instancetype)initWithNumber:(NSNumber *)number font:(UIFont *)font textColor:(UIColor *)textColor rowNumber:(NSUInteger)rowNumber; @@ -208,7 +212,7 @@ typedef NS_ENUM(NSUInteger, SignSetting) { @param rowNumber: the row count of DPScrollNumberLabel, it means the row count will be changeless @return the instance of DPScrollNumberLabel */ -- (instancetype)initWithNumber:(NSNumber *)number +- (nonnull instancetype)initWithNumber:(NSNumber *)number font:(UIFont *)font signSetting:(SignSetting)signSetting rowNumber:(NSUInteger)rowNumber; @@ -224,7 +228,7 @@ typedef NS_ENUM(NSUInteger, SignSetting) { @param rowNumber: the row count of DPScrollNumberLabel, it means the row count will be changeless @return the instance of DPScrollNumberLabel */ -- (instancetype)initWithNumber:(NSNumber *)number +- (nonnull instancetype)initWithNumber:(NSNumber *)number font:(UIFont *)font textColor:(UIColor *)textColor signSetting:(SignSetting)signSetting diff --git a/DPScrollNumberLabel/DPScrollNumberLabel.m b/DPScrollNumberLabel/DPScrollNumberLabel.m index e1fc0de..9ef2bf4 100644 --- a/DPScrollNumberLabel/DPScrollNumberLabel.m +++ b/DPScrollNumberLabel/DPScrollNumberLabel.m @@ -63,7 +63,6 @@ @interface DPScrollNumberLabel() @property (nonatomic, strong) NSNumber *targetNumber; @property (nonatomic, strong) NSMutableArray *cellArray; @property (nonatomic, strong) UILabel *signCell; -@property (nonatomic, assign) CGFloat fontSize; @property (nonatomic, assign) NSUInteger rowNumber; @property (nonatomic, strong) NSMutableArray *taskQueue; @property (nonatomic, assign) BOOL isAnimating; @@ -72,8 +71,6 @@ @interface DPScrollNumberLabel() @property (nonatomic, assign) CGFloat signCellHeight; @property (nonatomic, assign) NSInteger finishedAnimationCount; @property (nonatomic, assign) NSUInteger maxRowNumber; -@property (nonatomic, strong) UIColor *textColor; -@property (nonatomic, strong) UIFont *font; @property (nonatomic, assign) SignSetting signSetting; @property (nonatomic, assign) NSUInteger signRow; @property (nonatomic, assign) BOOL fixedRowNumber; @@ -623,7 +620,23 @@ - (CGFloat)getIntervalWithPreviousNumber:(NSInteger)previousNumber targetNumber: } -#pragma mark - Getters +#pragma mark - Getters & Setters + +- (void)setTextColor:(UIColor *)textColor { + _textColor = textColor; + [self.cellArray enumerateObjectsUsingBlock:^(UILabel * _Nonnull label, NSUInteger idx, BOOL * _Nonnull stop) { + label.textColor = textColor; + }]; + self.signCell.textColor = textColor; +} + +- (void)setFont:(UIFont *)font { + _font = font; + [self.cellArray enumerateObjectsUsingBlock:^(UILabel * _Nonnull label, NSUInteger idx, BOOL * _Nonnull stop) { + label.font = font; + }]; + self.signCell.font = font; +} - (UILabel *)makeNumberCell { UILabel *cell = [[UILabel alloc] init]; From 0e1d2f058c014d8799794ad77923b4958bc14bde Mon Sep 17 00:00:00 2001 From: mlch911 Date: Thu, 25 Apr 2024 16:07:28 +0800 Subject: [PATCH 4/6] Fix UI Bug --- DPScrollNumberLabel/DPScrollNumberLabel.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DPScrollNumberLabel/DPScrollNumberLabel.m b/DPScrollNumberLabel/DPScrollNumberLabel.m index 9ef2bf4..ed28404 100644 --- a/DPScrollNumberLabel/DPScrollNumberLabel.m +++ b/DPScrollNumberLabel/DPScrollNumberLabel.m @@ -657,7 +657,7 @@ - (UILabel *)signCell { _signCell.text = @"-\n \n "; break; case SignSettingUnsigned: - _signCell.text = @" \n \n "; + _signCell.text = @""; break; case SignSettingSigned: _signCell.text = @"-\n \n+"; From 1361a957e3fab5bb19cee346f59d5335bb0cc795 Mon Sep 17 00:00:00 2001 From: mlch911 Date: Thu, 23 May 2024 17:00:18 +0800 Subject: [PATCH 5/6] Fix: setFont --- DPScrollNumberLabel/DPScrollNumberLabel.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/DPScrollNumberLabel/DPScrollNumberLabel.m b/DPScrollNumberLabel/DPScrollNumberLabel.m index ed28404..866ecc5 100644 --- a/DPScrollNumberLabel/DPScrollNumberLabel.m +++ b/DPScrollNumberLabel/DPScrollNumberLabel.m @@ -632,10 +632,22 @@ - (void)setTextColor:(UIColor *)textColor { - (void)setFont:(UIFont *)font { _font = font; + + CGRect rect = [numberCellText boundingRectWithSize:CGSizeZero + options:NSStringDrawingUsesLineFragmentOrigin + attributes:@{NSFontAttributeName:self.font} + context:nil]; + self.cellWidth = rect.size.width; + self.numberCellHeight = rect.size.height; + self.signCellHeight = rect.size.height * signCellLineCount / numberCellLineCount; [self.cellArray enumerateObjectsUsingBlock:^(UILabel * _Nonnull label, NSUInteger idx, BOOL * _Nonnull stop) { label.font = font; + label.frame = CGRectMake((self.rowNumber + self.signRow - 1 - idx) * self.cellWidth, 0, self.cellWidth, self.numberCellHeight); }]; self.signCell.font = font; + self.signCell.frame = CGRectMake(0, 0, self.cellWidth, self.signCellHeight); + self.bounds = CGRectMake(0, 0, (self.rowNumber + self.signRow) * self.cellWidth, self.numberCellHeight / numberCellLineCount); + [self invalidateIntrinsicContentSize]; } - (UILabel *)makeNumberCell { From 67b50f5fce581235c5cde126363bb93f5e752658 Mon Sep 17 00:00:00 2001 From: mlch911 Date: Mon, 27 May 2024 14:08:35 +0800 Subject: [PATCH 6/6] =?UTF-8?q?Update:=20=E6=94=AF=E6=8C=81=E8=BF=9E?= =?UTF-8?q?=E8=B4=AF=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DPScrollNumberLabel/DPScrollNumberLabel.h | 5 +++ DPScrollNumberLabel/DPScrollNumberLabel.m | 40 ++++++++++++++++++----- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/DPScrollNumberLabel/DPScrollNumberLabel.h b/DPScrollNumberLabel/DPScrollNumberLabel.h index 91f3d9f..25573c8 100644 --- a/DPScrollNumberLabel/DPScrollNumberLabel.h +++ b/DPScrollNumberLabel/DPScrollNumberLabel.h @@ -36,6 +36,11 @@ typedef NS_ENUM(NSUInteger, SignSetting) { @property (nonatomic, strong) UIColor *textColor; +/// By default, when animate from 0 to 9 or from 9 to 0, there will be a big reverse animtation. Enable continuing animation by this. +@property (nonatomic, assign) BOOL continuingAnimation; + +@property (nonatomic, copy) void (^logBlock)(NSString *); + /** dynamic init method, the instance created by this method have a dynamic row count, it's row will change with the value you setting diff --git a/DPScrollNumberLabel/DPScrollNumberLabel.m b/DPScrollNumberLabel/DPScrollNumberLabel.m index 866ecc5..4729f09 100644 --- a/DPScrollNumberLabel/DPScrollNumberLabel.m +++ b/DPScrollNumberLabel/DPScrollNumberLabel.m @@ -164,6 +164,7 @@ - (instancetype)initWithNumber:(NSNumber *)number font:(UIFont *)font textColor: self.rowNumber = (rowNumber > 0 && rowNumber <= 8) ? rowNumber : 0; self.maxRowNumber = (self.rowNumber == 0) ? 8 : rowNumber; self.signSetting = signSetting; + self.logBlock = nil; [self commonInit]; } return self; @@ -344,6 +345,7 @@ - (void)playAnimationWithChange:(NSInteger)changeValue previousNumber:(NSNumber NSArray *repeatCountArray = [self getRepeatTimesWithChangeNumber:changeValue targetNumber:self.targetNumber.integerValue]; NSArray *targetDisplayNums = [self getEachCellValueArrayWithTargetNumber:self.targetNumber.integerValue]; + NSArray *previousDisplayNums = [self getEachCellValueArrayWithTargetNumber:previousNumber.integerValue]; if (interval == 0) { interval = [self getIntervalWithPreviousNumber:previousNumber.integerValue targetNumber:self.targetNumber.integerValue]; @@ -358,11 +360,12 @@ - (void)playAnimationWithChange:(NSInteger)changeValue previousNumber:(NSNumber NSNumber *repeat = [repeatCountArray objectAtIndex:i]; NSInteger repeatCount = repeat.integerValue; NSNumber *willDisplayNum = [targetDisplayNums objectAtIndex:i]; + NSNumber *previousDisplayNum = [previousDisplayNums objectAtIndex:i]; UILabel *cell = [self.cellArray objectAtIndex:i]; CGFloat startDuration = 0; if (repeatCount == 0) { - [self makeSingleAnimationWithCell:cell duration:interval delay:delay animationCount:repeatCountArray.count displayNumber:willDisplayNum.integerValue]; + [self makeSingleAnimationWithCell:cell duration:interval delay:delay animationCount:repeatCountArray.count displayNumber:willDisplayNum.integerValue previousNumber:previousDisplayNum.integerValue]; }else { if (direction == ScrollAnimationDirectionIncrease) { @@ -413,41 +416,56 @@ - (void)makeMultiAnimationWithCell:(UILabel *)cell [UIView animateWithDuration:attribute.startDuration delay:attribute.startDelay options:UIViewAnimationOptionCurveEaseIn animations:^{ [self moveNumberCell:cell toNumber:(direction == ScrollAnimationDirectionIncrease)? 10 : 0 sign:attribute.sign]; } completion:^(BOOL finished) { - NSLog(@"start animation finish!"); + self.logBlock(@"start animation finish!"); [self moveNumberCell:cell toNumber:(direction == ScrollAnimationDirectionIncrease)? 0 : 10 sign:attribute.sign]; if (attribute.cycleDuration == 0) { [UIView animateWithDuration:attribute.endDuration delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ [self moveNumberCell:cell toNumber:attribute.targetNumber sign:attribute.sign]; } completion:^(BOOL finished) { [self oneAnimationDidFinishedWithTotalCount:count]; - NSLog(@"end animation finish!"); + self.logBlock(@"end animation finish!"); }]; }else { [UIView animateWithDuration:attribute.cycleDuration delay:0 options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionRepeat animations:^{ [UIView setAnimationRepeatCount:attribute.repeatCount]; [self moveNumberCell:cell toNumber:(direction == ScrollAnimationDirectionIncrease) ? 10 : 0 sign:attribute.sign]; } completion:^(BOOL finished) { - NSLog(@"cycle animation finish!"); + self.logBlock(@"cycle animation finish!"); [self moveNumberCell:cell toNumber:(direction == ScrollAnimationDirectionIncrease)?0 : 10 sign:attribute.sign]; [UIView animateWithDuration:attribute.endDuration delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ [self moveNumberCell:cell toNumber:attribute.targetNumber sign:attribute.sign]; } completion:^(BOOL finished) { [self oneAnimationDidFinishedWithTotalCount:count]; - NSLog(@"end animation finish!"); + self.logBlock(@"end animation finish!"); }]; }]; } }]; } -- (void)makeSingleAnimationWithCell:(UILabel *)cell duration:(CGFloat)duration delay:(CGFloat)delay animationCount:(NSInteger)count displayNumber:(NSInteger)displayNumber{ +- (void)makeSingleAnimationWithCell:(UILabel *)cell duration:(CGFloat)duration delay:(CGFloat)delay animationCount:(NSInteger)count displayNumber:(NSInteger)displayNumber previousNumber:(NSInteger)previousNumber { int sign = displayNumber >= 0 ? 1 : -1; - + void (^completionBlock)(void); + + if (self.continuingAnimation) { + if (previousNumber == 0 && displayNumber == 9) { + [self moveNumberCell:cell toNumber:10 sign:sign]; + } else if (previousNumber == 9 && displayNumber == 0) { + displayNumber = 10; + completionBlock = ^{ + [self moveNumberCell:cell toNumber:0 sign:sign]; + }; + } + } + [UIView animateWithDuration:duration delay:delay options:UIViewAnimationOptionCurveEaseOut animations:^{ [self moveNumberCell:cell toNumber:displayNumber sign:sign]; } completion:^(BOOL finished) { + if (completionBlock) { + completionBlock(); + } [self oneAnimationDidFinishedWithTotalCount:count]; - NSLog(@"single animation finish!"); + self.logBlock(@"single animation finish!"); }]; } @@ -547,7 +565,7 @@ - (NSInteger)calculateNumberRow:(NSInteger)number { return numberRow; } -- (void)moveNumberCell:(UILabel *)cell toNumber:(NSInteger)number sign:(NSInteger)sign{ +- (void)moveNumberCell:(UILabel *)cell toNumber:(NSInteger)number sign:(NSInteger)sign { CGFloat x = cell.frame.origin.x; CGFloat floatNumber = abs((int)number); CGFloat y = - self.numberCellHeight / numberCellLineCount * 10 - sign * ((CGFloat)floatNumber / numberCellLineCount) * self.numberCellHeight; @@ -650,6 +668,10 @@ - (void)setFont:(UIFont *)font { [self invalidateIntrinsicContentSize]; } +- (void)setLogBlock:(void (^)(NSString *))logBlock { + _logBlock = logBlock ?: (^(NSString *l) {}); +} + - (UILabel *)makeNumberCell { UILabel *cell = [[UILabel alloc] init]; cell.font = self.font;