自定义UIView实现在屏幕上画画并记录路径
来源:互联网 发布:5g云网络wlxiu 编辑:程序博客网 时间:2024/04/30 15:07
#import "paint.h"
@implementation paint
- (void)awakeFromNib
{
这个方法只会执行一次
self.path = [[UIBezierPathalloc] init];
self.path.lineJoinStyle = kCGLineJoinRound;
self.path.lineCapStyle = kCGLineCapRound;
self.path.lineWidth =5;
初始化一个记录路径的数组
_pathArray = [[NSMutableArrayalloc]init];
}
//必须实现的两个绘图方法
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//get the starting point
CGPoint point = [[touches anyObject] locationInView:self];
//move the path drawing cursor to the starting point
[self.pathmoveToPoint:point];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
//get the current point
CGPoint point = [[touches anyObject] locationInView:self];
//add a new line segment to our path
[self.pathaddLineToPoint:point];
//redraw the view
[selfsetNeedsDisplay];
}
//绘制方法
- (void)drawRect:(CGRect)rect
{
//draw path
[[UIColorclearColor] setFill];
[[UIColorredColor] setStroke];
[self.pathstroke];
//添加路径
[_pathArray addObject:self.path];
}
set和get方法用来传pathArray的值
- (NSArray *)pathArray
{
return_pathArray;
}
- (void)setPathArray:(NSMutableArray *)pathArray
{
_pathArray = pathArray;
}
暴漏一个draw方法,实现在其他类中调用自动绘图方法
- (void)draw:(UIBezierPath *)apath
{
self.path = apath;
[selfsetNeedsDisplay];
}
@end
- 自定义UIView实现在屏幕上画画并记录路径
- iOS判断UIView是否显示在屏幕上
- iOS判断UIView是否显示在屏幕上
- 在bmp上写字,画画等
- 如何在图上写字,或者画画。
- 如何在SAP屏幕上自定义按钮?
- c#实现截取屏幕并保存到硬盘及显示在界面上
- 如何实现在屏幕上有漂亮的刀光效果并有星星环绕
- 【C语言】如何实现多行字符串的输入 并 将文本打印在屏幕上?
- 自定义View实现手指在屏幕上绘制线条(贝塞尔曲线处理)(一)
- 屏幕录制在h323上的实现
- Android 自定义控件的画画扳的简单实现
- 编写一个组合鼠标事件和键盘事件的程序,该程序模拟一个电子白板,用户用鼠标在白板上画画,并通过键盘在上面写字
- 读取文件并在屏幕上显示内容
- 从键盘读入数据并显示在屏幕上
- COCOS2DX-3.0截取当前屏幕并在ANDROID上分享
- ALV在标准按钮上增加自定义按钮,并实现文本及功能互相切换
- 使用FileInputStream类, 实现从磁盘读取本应用程序源代码文件,并将文件内容显示在屏幕上。
- 欧拉项目18题
- ssh不到Linux虚拟机几个原因
- 黑色的夜
- Animation & Property Animation 使用
- Linux系统安装
- 自定义UIView实现在屏幕上画画并记录路径
- IOS程序编译报错
- 将一个字节存储的2位BCD码解码
- 浅析setw()函数
- Python中*args 和**kwargs的用法
- 104-在xcode6中使用pch文件
- mongodb 基本操作
- Android 自定义view实现水波纹效果
- 数据挖掘算法学习(一)K-Means算法