文字渐渐显示效果
来源:互联网 发布:国内域名国外空间 编辑:程序博客网 时间:2024/04/30 16:38
#import "DMAnimationLayer.h"@interface DMAnimationLayer()@property (nonatomic, retain) CAShapeLayer *pathLayer;@property (nonatomic, retain) CALayer *penLayer;@end@implementation DMAnimationLayer+(void)createAnimationLayerWithString:(NSString*)string andRect:(CGRect)rect andView:(UIView *)view andFont:(UIFont*)ui_font andStrokeColor:(UIColor*)color{ DMAnimationLayer * animationLayer = [DMAnimationLayer layer]; animationLayer.frame = rect; [view.layer addSublayer:animationLayer]; if (animationLayer.pathLayer != nil) { [animationLayer.penLayer removeFromSuperlayer]; [animationLayer.pathLayer removeFromSuperlayer]; animationLayer.pathLayer = nil; animationLayer.penLayer = nil; } CTFontRef font =CTFontCreateWithName((CFStringRef)ui_font.fontName, ui_font.pointSize, NULL); CGMutablePathRef letters = CGPathCreateMutable(); //这里设置画线的字体和大小 NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys: (__bridge id)font, kCTFontAttributeName, nil]; NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:string attributes:attrs]; CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)attrString); CFArrayRef runArray = CTLineGetGlyphRuns(line); // for each RUN for (CFIndex runIndex = 0; runIndex < CFArrayGetCount(runArray); runIndex++) { // Get FONT for this run CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runArray, runIndex); CTFontRef runFont = CFDictionaryGetValue(CTRunGetAttributes(run), kCTFontAttributeName); // for each GLYPH in run for (CFIndex runGlyphIndex = 0; runGlyphIndex < CTRunGetGlyphCount(run); runGlyphIndex++) { CFRange thisGlyphRange = CFRangeMake(runGlyphIndex, 1); CGGlyph glyph; CGPoint position; CTRunGetGlyphs(run, thisGlyphRange, &glyph); CTRunGetPositions(run, thisGlyphRange, &position); { CGPathRef letter = CTFontCreatePathForGlyph(runFont, glyph, NULL); CGAffineTransform t = CGAffineTransformMakeTranslation(position.x, position.y); CGPathAddPath(letters, &t, letter); CGPathRelease(letter); } } } CFRelease(line); UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:CGPointZero]; [path appendPath:[UIBezierPath bezierPathWithCGPath:letters]]; CGPathRelease(letters); CFRelease(font);// CAShapeLayer *pathLayer = [CAShapeLayer layer]; pathLayer.frame = CGRectMake(0, 0, rect.size.width, rect.size.height -230); pathLayer.bounds = CGPathGetBoundingBox(path.CGPath); pathLayer.geometryFlipped = YES; pathLayer.path = path.CGPath; pathLayer.strokeColor = [color CGColor]; pathLayer.fillColor = nil; pathLayer.lineWidth = 1.0f; pathLayer.lineJoin = kCALineJoinBevel; [animationLayer addSublayer:pathLayer]; animationLayer.pathLayer = pathLayer; CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; pathAnimation.duration = 5.0; pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f]; pathAnimation.toValue = [NSNumber numberWithFloat:1.0f]; [animationLayer.pathLayer addAnimation:pathAnimation forKey:@"strokeEnd"]; CAKeyframeAnimation *penAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; penAnimation.duration = 5.0; penAnimation.path = animationLayer.pathLayer.path; penAnimation.calculationMode = kCAAnimationPaced; penAnimation.delegate = animationLayer; [animationLayer.penLayer addAnimation:penAnimation forKey:@"position"];}- (void) animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{ self.penLayer.hidden = YES;}@end第三方:https://github.com/overboming/ZCAnimatedLabel
0 0
- 文字渐渐显示效果
- 文字同步显示效果
- 文字滚动显示效果
- 以倒影效果显示文字
- 以投影效果显示文字
- 文字显示省略效果范例
- js 控制div 渐渐消失 渐渐出现效果
- UIView 渐渐出现 和渐渐消失了动画效果
- 简单的文字渐渐显效果
- 文字超长自动变成省略号显示效果
- CSS鼠标经过文字显示图片效果
- Android TextView 显示文字阴影效果
- Android文字显示效果小究
- js实现文字动态显示效果
- android显示TextView文字的倒影效果
- android显示TextView文字的倒影效果
- Android实现文字显示跑马灯效果
- jQuery标题文字淡入淡出显示效果
- 详解MySql优化步骤
- ActionListener的三种实现方法
- Oracle切换UNDO空间数据库后存储过程无法正常编译
- 处理一个关于binlog增量恢复很慢的问题
- valgrind 简介
- 文字渐渐显示效果
- redis总结
- 数据结构(王道)【线性表】【算法1.3】
- c++ template 实现一个简单的"栈"
- apache、php、mysql和phpmyadmin安装及环境配置
- 理解Python中的装饰器
- service
- Linux C语言strlcpy,strlcat函数
- 国内常用且有效的NTP服务器地址及IP(2016年2月)