[控件] 将字符串转换成贝塞尔曲线并执行动画
2023-09-14 08:57:16 时间
@property (nonatomic, strong) NSString *text;
@property (nonatomic, strong) UIFont *font;
@property (nonatomic, strong) UIColor *lineColor;
@property (nonatomic, assign) CGFloat lineWidth;
// Created by XianMingYou on 15/3/6. // Copyright (c) 2015年 XianMingYou. All rights reserved. #import "ShapeWordView.h" @interface ShapeWordView () @property (nonatomic, strong) CAShapeLayer *shapeLayer; @implementation ShapeWordView - (void)buildView { // 过滤数据 CGFloat lineWidth = (self.lineWidth = 0 ? 0.5 : self.lineWidth); UIFont *font = (self.font == nil ? [UIFont systemFontOfSize:18.f] : self.font); UIColor *lineColor = (self.lineColor == nil ? [UIColor blackColor] : self.lineColor); NSString *text = self.text; if (text == nil || text.length == 0) { return; // 初始化layer self.shapeLayer = [CAShapeLayer layer]; self.shapeLayer.frame = self.bounds; self.shapeLayer.lineWidth = lineWidth; self.shapeLayer.fillColor = [UIColor clearColor].CGColor; self.shapeLayer.strokeColor = lineColor.CGColor; self.shapeLayer.path = [UIBezierPath pathForMultilineString:text withFont:font maxWidth:self.bounds.size.width textAlignment:NSTextAlignmentCenter].CGPath; self.shapeLayer.bounds = CGPathGetBoundingBox(self.shapeLayer.path); self.shapeLayer.geometryFlipped = YES; self.shapeLayer.strokeEnd = 0.f; [self.layer addSublayer:self.shapeLayer]; - (void)percent:(CGFloat)percent animated:(BOOL)animated { if (animated) { if (percent = 0) { self.shapeLayer.strokeEnd = 0; } else if (percent 0 percent = 1) { self.shapeLayer.strokeEnd = percent; } else { self.shapeLayer.strokeEnd = 1.f; } else { if (percent = 0) { [CATransaction setDisableActions:YES]; self.shapeLayer.strokeEnd = 0; [CATransaction setDisableActions:NO]; } else if (percent 0 percent = 1) { [CATransaction setDisableActions:YES]; self.shapeLayer.strokeEnd = percent; [CATransaction setDisableActions:NO]; } else { [CATransaction setDisableActions:YES]; self.shapeLayer.strokeEnd = 1.f; [CATransaction setDisableActions:NO]; @end
使用:
Winform控件优化之Paint事件实现圆角组件(提取绘制圆角的扩展方法) Paint事件方法中实现圆角控件不要通过事件参数`e.ClipRectangle`获取控件区域范围,原因见最后介绍;注意设置控件背景透明(参见[Winform控件优化之背景透明那些事2...
WPF中将四个数字字符串值(比如: 10,10,300,300 )转为Rect 原文:WPF中将四个数字字符串值(比如: 10,10,300,300 )转为Rect RectConverter rectConverter = new RectConverter(); string parseString = viewportEntry.
利用WPF的ListView控件实现类似于Winform中DataGrid行背景色交替变换的效果,同时增加鼠标的悬停效果。
WPF绘制光滑连续贝塞尔曲线 原文:WPF绘制光滑连续贝塞尔曲线 WPF本身没有直接把点集合绘制成曲线的函数。可以通过贝塞尔曲线函数来绘制。 贝塞尔曲线类是:BezierSegment,三次贝塞尔曲线,通过两个控制点来控制开始和结束方向。
// Created by XianMingYou on 15/3/6. // Copyright (c) 2015年 XianMingYou. All rights reserved. #import "ShapeWordView.h" @interface ShapeWordView () @property (nonatomic, strong) CAShapeLayer *shapeLayer; @implementation ShapeWordView - (void)buildView { // 过滤数据 CGFloat lineWidth = (self.lineWidth = 0 ? 0.5 : self.lineWidth); UIFont *font = (self.font == nil ? [UIFont systemFontOfSize:18.f] : self.font); UIColor *lineColor = (self.lineColor == nil ? [UIColor blackColor] : self.lineColor); NSString *text = self.text; if (text == nil || text.length == 0) { return; // 初始化layer self.shapeLayer = [CAShapeLayer layer]; self.shapeLayer.frame = self.bounds; self.shapeLayer.lineWidth = lineWidth; self.shapeLayer.fillColor = [UIColor clearColor].CGColor; self.shapeLayer.strokeColor = lineColor.CGColor; self.shapeLayer.path = [UIBezierPath pathForMultilineString:text withFont:font maxWidth:self.bounds.size.width textAlignment:NSTextAlignmentCenter].CGPath; self.shapeLayer.bounds = CGPathGetBoundingBox(self.shapeLayer.path); self.shapeLayer.geometryFlipped = YES; self.shapeLayer.strokeEnd = 0.f; [self.layer addSublayer:self.shapeLayer]; - (void)percent:(CGFloat)percent animated:(BOOL)animated { if (animated) { if (percent = 0) { self.shapeLayer.strokeEnd = 0; } else if (percent 0 percent = 1) { self.shapeLayer.strokeEnd = percent; } else { self.shapeLayer.strokeEnd = 1.f; } else { if (percent = 0) { [CATransaction setDisableActions:YES]; self.shapeLayer.strokeEnd = 0; [CATransaction setDisableActions:NO]; } else if (percent 0 percent = 1) { [CATransaction setDisableActions:YES]; self.shapeLayer.strokeEnd = percent; [CATransaction setDisableActions:NO]; } else { [CATransaction setDisableActions:YES]; self.shapeLayer.strokeEnd = 1.f; [CATransaction setDisableActions:NO]; @end
使用:
// // ViewController.m // PathWord // Created by XianMingYou on 15/3/6. // Copyright (c) 2015年 XianMingYou. All rights reserved. #import "ViewController.h" #import "UIBezierPath+TextPaths.h" #import "ShapeWordView.h" @interface ViewController () UITableViewDelegate @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) ShapeWordView *shape; @implementation ViewController - (void)viewDidLoad { [super viewDidLoad];
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; self.tableView.delegate = self; [self.view addSubview:self.tableView]; self.shape = [[ShapeWordView alloc] initWithFrame:CGRectMake(10, 20, 290, 100)]; self.shape.lineColor = [UIColor redColor]; self.shape.text = @"YouXianMing"; self.shape.lineWidth = 0.5f; [self.shape buildView]; [self.view addSubview:self.shape]; - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat offsetY = - scrollView.contentOffset.y; if (offsetY = 0) { CGFloat percent = offsetY / 50; [self.shape percent:percent animated:NO]; @end
Winform控件优化之Paint事件实现圆角组件(提取绘制圆角的扩展方法) Paint事件方法中实现圆角控件不要通过事件参数`e.ClipRectangle`获取控件区域范围,原因见最后介绍;注意设置控件背景透明(参见[Winform控件优化之背景透明那些事2...
WPF中将四个数字字符串值(比如: 10,10,300,300 )转为Rect 原文:WPF中将四个数字字符串值(比如: 10,10,300,300 )转为Rect RectConverter rectConverter = new RectConverter(); string parseString = viewportEntry.
利用WPF的ListView控件实现类似于Winform中DataGrid行背景色交替变换的效果,同时增加鼠标的悬停效果。
WPF绘制光滑连续贝塞尔曲线 原文:WPF绘制光滑连续贝塞尔曲线 WPF本身没有直接把点集合绘制成曲线的函数。可以通过贝塞尔曲线函数来绘制。 贝塞尔曲线类是:BezierSegment,三次贝塞尔曲线,通过两个控制点来控制开始和结束方向。
相关文章
- [控件] 将字符串转换成贝塞尔曲线并执行动画
- 按钮在执行frame动画的时候怎么响应触发事件?
- POP动画[3]
- 动画效果解析工厂:Mask 动画
- [翻译] POP Facebook的动画开源库
- Dojo动画原理解析
- android 动画基础绘——帧动画(三)
- uni-app:uni-transition动画分多个step执行(hbuilderx 3.7.3)
- 74行代码实现浪漫的红心下落的动画效果
- 前端进阶必学必会动画学习之Animate.css的使用与解析:一个强大而酷炫的CSS3动画库Animate.css使用方法教程
- Qt QPropertyAnimation 几行代码快速制作流畅的动画效果
- 【动画详解原理系列】2.多线程并发编程与锁
- CSS3与页面布局学习总结(六)——CSS3新特性(阴影、动画、渐变、变形、伪元素等)
- Canvas组件:画布,可以实现动画操作。