当前位置: 首页 > news >正文

网站建设行业增长率哈尔滨网络公司

网站建设行业增长率,哈尔滨网络公司,企业做电商网站有哪些内容,sql2005做网站资源下载地址:https://download.csdn.net/download/sheziqiong/85813646 资源下载地址:https://download.csdn.net/download/sheziqiong/85813646 需要具备iOS绘画基础知识 完成一个最基本的涂鸦板给涂鸦板加上颜色选择功能,和笔触粗细功能 …

资源下载地址:https://download.csdn.net/download/sheziqiong/85813646
资源下载地址:https://download.csdn.net/download/sheziqiong/85813646

需要具备iOS绘画基础知识

  • 完成一个最基本的涂鸦板
  • 给涂鸦板加上颜色选择功能,和笔触粗细功能

效果图:

完成一个最基本的涂鸦板

下载代码后见文件PaintViewV01,看效果请在ViewController中找到PaintView,换成PaintView01

步骤和原理

  • 重写uiview的 init、initWithFrame方法,主要是添加一个白色的背景色
  • 重写touchesBegan、touchesMoved、touchesEnded,作用是接收屏幕触摸的坐标,手指接触uiview后会依次执行这三个方法。 其中重写touchesBegan和重写touchesEnded只在开始和结束执行一次,而手指在移动的过程中,会多次执行touchesMoved
  • 重写drawRect方法,根据用户手指的移动,画出涂鸦

代码

# import "PaintViewV01.h"@implementation PaintViewV01{//画的线路径的集合,内部是NSMutableArray类型NSMutableArray *paths;
}http://www.biyezuopin.vip-(instancetype)init{self = [super init];if (self) {//初始化uiview的样式[self paintViewInit];}return  self;
}
-(instancetype)initWithFrame:(CGRect)frame{self = [super initWithFrame:frame];if (self) {//初始化uiview的样式[self paintViewInit];}return  self;
}//初始化paintViewInit样式和数据
-(void)paintViewInit{//添加背景色self.backgroundColor = [UIColor whiteColor];//初始化路径集合paths = [[NSMutableArray alloc]init];
}-(void)drawRect:(CGRect)rect{//必须调用父类drawRect方法,否则 UIGraphicsGetCurrentContext()获取不到context[super drawRect:rect];//获取ctxCGContextRef ctx = UIGraphicsGetCurrentContext();//渲染所有路径for (int i=0; i<paths.count; i++) {NSMutableArray *pathPoints = [paths objectAtIndex:i];CGMutablePathRef path = CGPathCreateMutable();for (int j=0; j<pathPoints.count; j++) {CGPoint point = [[pathPoints objectAtIndex:j]CGPointValue] ;if (j==0) {CGPathMoveToPoint(path, &CGAffineTransformIdentity, point.x,point.y);}else{CGPathAddLineToPoint(path, &CGAffineTransformIdentity, point.x, point.y);}}//路径添加到ctCGContextAddPath(ctx, path);//描边CGContextStrokePath(ctx);}
}-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{//创建一个路径,放到paths里面NSMutableArray *path = [[NSMutableArray alloc]init];[paths addObject:path];
}http://www.biyezuopin.vip-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{//获取当前路径NSMutableArray *path = [paths lastObject];//获取当前点CGPoint movePoint = [[touches anyObject]locationInView:self];NSLog(@"touchesMoved     x:%f,y:%f",movePoint.x,movePoint.y);//CGPint要通过NSValue封装一次才能放入NSArray[path addObject:[NSValue valueWithCGPoint:movePoint]];//通知重新渲染界面,这个方法会重新调用UIView的drawRect:(CGRect)rect方法[self setNeedsDisplay];
}-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{}@end

完成后,就可以画画了,不过只能画固定粗细的黑色笔画,下面,我我们增加彩色笔画和控制粗细的功能


给涂鸦板加上颜色和笔触粗细选择的功能

下载代码后见文件PaintViewV02,看效果请在ViewController中找到PaintView,换成PaintView02

步骤

  • 增加一个数据对象,封装笔触pathPoint、笔触颜色、笔触粗细
  • 修改变量名称,增加变量
  • 修改界面,添加色板,和笔触粗细选择器
  • 修改原来的touchesBegan,touchesMoved方法,将选择的颜色数据和粗细数据封装
  • 修改drawRect方法

增加一个数据对象,封装笔触pathPoint、笔触颜色、笔触粗细

# import <Foundation/Foundation.h>
# import <UIKit/UIKit.h>@interface PaintStep : NSObject{@public//路径NSMutableArray *pathPoints;//颜色CGColorRef color;//笔画粗细float strokeWidth;
}@end
# import "PaintStep.h"@implementation PaintStep@end

修改变量名称,增加变量,

paths 改名为 paintSteps,并增加currColor和slider两个变量

//屏幕的宽高,做自适应用的
# define width  [UIScreen mainScreen].bounds.size.width
# define height [UIScreen mainScreen].bounds.size.height@implementation PaintViewV02{//画的线路径的集合,内部是NSMutableArray类型NSMutableArray *paintSteps;//当前选中的颜色UIColor *currColor;//当前笔触粗细选择器UISlider *slider;}

修改界面,添加色板,和笔触粗细选择器

(void)paintViewInit 方法增加对两个方法的调用 —

-(void)paintViewInit 方法增加....//创建色板[self createColorBord];//创建笔触粗细选择器[self createStrokeWidthSlider];
}

创建色板和创建笔触粗细选择器的实现


//创建色板
-(void)createColorBord{//默认当前笔触颜色是黑色currColor = [UIColor blackColor];//色板的viewUIView *colorBoardView = [[UIView alloc]initWithFrame:CGRectMake(0, 20, width, 20)];[self addSubview:colorBoardView];//色板样式colorBoardView.layer.borderWidth = 1;colorBoardView.layer.borderColor = [UIColor blackColor].CGColor;//创建每个色块NSArray *colors = [NSArray arrayWithObjects:[UIColor blackColor],[UIColor redColor],[UIColor blueColor],[UIColor greenColor],[UIColor yellowColor],[UIColor brownColor],[UIColor orangeColor],[UIColor whiteColor],[UIColor orangeColor],[UIColor purpleColor],[UIColor cyanColor],[UIColor lightGrayColor], nil];for (int i =0; i<colors.count; i++) {UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake((width/colors.count)*i, 0, width/colors.count, 20)];[colorBoardView addSubview:btn];[btn setBackgroundColor:colors[i]];[btn addTarget:self action:@selector(changeColor:) forControlEvents:UIControlEventTouchUpInside];}}//切换颜色
-(void)changeColor:(id)target{UIButton *btn = (UIButton *)target;currColor = [btn backgroundColor];
}//创建笔触粗细选择器
-(void)createStrokeWidthSlider{slider = [[UISlider alloc]initWithFrame:CGRectMake(0, 50, width, 20)];slider.maximumValue = 20;slider.minimumValue = 1;[self addSubview:slider];
}

完成后,我们的画板就可以画出彩色的笔画,控制粗细了。之后,我会继续给画板增加一些功能,并把方法写出来。


资源下载地址:https://download.csdn.net/download/sheziqiong/85813646
资源下载地址:https://download.csdn.net/download/sheziqiong/85813646

http://www.lbrq.cn/news/2808289.html

相关文章:

  • 找大学生做家教去哪个网站找好新品推广计划与方案
  • 深圳网站设计权威乐云践新目前引流最好的平台
  • 太原网站建设费用seo优化的优点
  • 门户网站开发过程视频外贸快车
  • 建设银行网站个人客户seo优化网站优化排名
  • 医院网站后台模板seo有名气的优化公司
  • 南京建设工程质量监督站网站做网络推广怎么收费
  • 可在哪些网站做链接dw如何制作网页
  • 设计干货很多的网站优化疫情政策
  • 网站做301好不好百度收录入口在哪里查询
  • 商业网站建设教程乐陵seo优化
  • 深圳政府门户网站设计亮点网站优化公司上海
  • wordpress 国人原创百度seo关键词
  • 自己做网站用哪个软件百度教育app
  • 网站建设设计服务宽带营销策略
  • 有什么做旅游攻略的网站今天最新新闻国内大事件
  • 培训中心网站建设论文aso优化服务
  • 幸运28网站开发竞价推广平台
  • 建设网站坂田seo 专业
  • 厦门做网站建设seo兼职平台
  • 广发证券 网站谁做的360网站排名优化
  • 电子商务系统 网站建设长春网站提升排名
  • 网页和网站做哪个好用网站seo外包公司有哪些
  • 网站关键词可以做几个广州疫情今天最新消息
  • 保定专业网站制作seo搜索引擎优化步骤
  • 小猪网站怎么做的百度贴吧免费发布信息
  • 怀化物流网站建设报价b站推广网站
  • 营销型网站建设选择题电商运营去哪里学比较好
  • 建一个网页网站驾校推广网络营销方案
  • 杭州网站建设哪家比较好b站推广网站入口202
  • AI生成技术报告:GaussDB与openGauss的HTAP功能全面对比
  • 使用tauri打包cocos小游戏,并在抖音小玩法中启动,拿到启动参数token
  • 2025软件供应链安全技术路线未来趋势预测
  • STM32G4-比较器
  • 【TrOCR】根据任务特性设计词表vocab.json
  • 2025-08-21 Python进阶2——数据结构