添加下划线动画

正在输入的数字,有下划线是添加动画
This commit is contained in:
MengLiMing
2016-10-26 15:39:47 +08:00
parent 886f4d14bb
commit fdf050ee94
4 changed files with 56 additions and 6 deletions

View File

@@ -29,6 +29,9 @@ typedef NS_ENUM(NSInteger,CodeViewType) {
//是否需要输入之后清空,再次输入使用,默认为NO
@property (nonatomic, assign) BOOL emptyEditEnd;
//是否添加下划线的动画,默认NO
@property (nonatomic, assign) BOOL underLineAnimation;
- (instancetype)initWithFrame:(CGRect)frame
num:(NSInteger)num
lineColor:(UIColor *)lColor

View File

@@ -60,6 +60,8 @@
textFont = [UIFont boldSystemFontOfSize:font];
_underLineAnimation = NO;
_emptyEditEnd = NO;
//self
NSAssert(textFont.lineHeight < self.frame.size.height, @"设置的字体高度应该小于self的高");
@@ -73,13 +75,16 @@
return self;
}
- (void)setUnderLineAnimation:(BOOL)underLineAnimation {
_underLineAnimation = underLineAnimation;
if (underLineAnimation && !_hasUnderLine) {
self.hasUnderLine = YES;
}
}
- (void)setHasSpaceLine:(BOOL)hasSpaceLine {
_hasSpaceLine = hasSpaceLine;
if (hasSpaceLine) {
[self addSpaceLine];
}
}
- (void)setHasUnderLine:(BOOL)hasUnderLine {
@@ -113,6 +118,10 @@
[self underLineHidden];
[self addUnderLineAnimation];
if (length == lineNum && self.EndEditBlcok) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.EndEditBlcok(_textField.text);
@@ -136,6 +145,8 @@
[self setNeedsDisplay];
[self underLineHidden];
}
[self addUnderLineAnimation];
}
@@ -189,6 +200,9 @@
[self.layer addSublayer:line];
[self.underlineArr addObject:line];
}
[self addUnderLineAnimation];
}
//线
@@ -257,5 +271,37 @@
#pragma mark - 线,线
- (void)addUnderLineAnimation {
if (_underLineAnimation) {
if (textArray.count >= lineNum) {
return;
}
for (NSInteger i = 0; i < _underlineArr.count; i ++) {
CAShapeLayer *line = _underlineArr[i];
if (i == textArray.count) {
[line addAnimation:[self opacityAnimation] forKey:@"kOpacityAnimation"];
} else {
[line removeAnimationForKey:@"kOpacityAnimation"];
}
}
}
}
- (CABasicAnimation *)opacityAnimation {
CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
opacityAnimation.fromValue = @(1.0);
opacityAnimation.toValue = @(0.0);
opacityAnimation.duration = .8;
opacityAnimation.repeatCount = HUGE_VALF;
opacityAnimation.removedOnCompletion = NO;
opacityAnimation.fillMode = kCAFillModeForwards;
opacityAnimation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
return opacityAnimation;
}
@end

View File

@@ -42,12 +42,13 @@
switch (i) {
case 0:
{
//线
v.hasUnderLine = YES;
// //线
// v.hasUnderLine = YES;
//线
v.hasSpaceLine = YES;
//
v.emptyEditEnd = YES;
v.underLineAnimation = YES;
//
v.codeType = CodeViewTypeCustom;
}