日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ios 三种颜色画笔和橡皮擦的画图板demo

發(fā)布時間:2025/4/16 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ios 三种颜色画笔和橡皮擦的画图板demo 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

demo功能:三種顏色畫筆和橡皮擦的畫圖板demo 【iphone 6.1 測試通過】

demo說明:項目中PaintView.m 是demo的畫板部分,PaintView和三個顏色按鈕添加到ViewController的view中。構(gòu)成程序主界面。

demo截屏:


demo主要代碼:PaintView.m 畫板view部分

?

#import "PaintView.h" #import <QuartzCore/QuartzCore.h>@implementation PaintView @synthesize paintColor = _paintColor; @synthesize erase; - (id)initWithFrame:(CGRect)frame {self = [super initWithFrame:frame];if (self) {self.layer.shadowColor = [UIColor blackColor].CGColor;self.layer.shadowOpacity = 0.8;self.layer.shadowOffset = CGSizeMake(5, 5);self.backgroundColor = [UIColor whiteColor];self.paintColor = [UIColor blackColor];// Initialization codelinesArray = [[NSMutableArray alloc]init];UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc]initWithTarget:selfaction:@selector(panGesture:)];[self addGestureRecognizer:panGesture];[panGesture release];}return self; }- (void)dealloc {[linesArray release];[_paintColor release];[super dealloc]; }// Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect {// Drawing codeCGContextRef context = UIGraphicsGetCurrentContext();CGContextSetLineWidth(context, 20);//NSLog(@"color:%@",_paintColor);for (NSDictionary *lineDic in linesArray) {UIColor *lineColor = [lineDic objectForKey:@"color"];CGContextSetStrokeColorWithColor(context, lineColor.CGColor);CGMutablePathRef paintPath = CGPathCreateMutable();NSArray *linePointArray = [lineDic objectForKey:@"line"];for (NSInteger i=0; i<linePointArray.count; i++) {CGPoint point = [[linePointArray objectAtIndex:i]CGPointValue];if (i==0) {//CGContextMoveToPoint(context, point.x, point.y);CGPathMoveToPoint(paintPath, NULL, point.x, point.y);}else {//CGContextAddLineToPoint(context, point.x, point.y);CGPathAddLineToPoint(paintPath, NULL, point.x, point.y);}}CGContextAddPath(context, paintPath);CGContextStrokePath(context);if ([lineDic objectForKey:@"eraseArray"]) {//NSLog(@"color:%@",lineColor);NSMutableArray *eraseArray = [lineDic objectForKey:@"eraseArray"];CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);CGMutablePathRef paintPath = CGPathCreateMutable();for (NSInteger i=0; i<eraseArray.count; i++) {CGPoint point = [[eraseArray objectAtIndex:i]CGPointValue];//NSLog(@"erase point:%@",NSStringFromCGPoint(point));if (i==0) {//CGContextMoveToPoint(context, point.x, point.y);CGPathMoveToPoint(paintPath, NULL, point.x, point.y);}else {//CGContextAddLineToPoint(context, point.x, point.y);CGPathAddLineToPoint(paintPath, NULL, point.x, point.y);}}CGContextAddPath(context, paintPath);CGContextStrokePath(context);}} }-(void)panGesture:(UIPanGestureRecognizer*)thePan{CGPoint touchPoint = [thePan locationInView:self];if (self.erase) {if (thePan.state==UIGestureRecognizerStateChanged) {for (NSMutableDictionary *lineDic in linesArray) {NSMutableArray *linePointArray = [lineDic objectForKey:@"line"];for (NSInteger i=0; i<linePointArray.count; i++) {CGPoint point = [[linePointArray objectAtIndex:i]CGPointValue];CGFloat distance = powf(point.x-touchPoint.x,point.y-touchPoint.y);if (distance<20) {NSMutableArray *eraseArray;if ([lineDic objectForKey:@"eraseArray"]) {eraseArray = [lineDic objectForKey:@"eraseArray"];}else {eraseArray = [NSMutableArray array];}[eraseArray addObject:[NSValue valueWithCGPoint:touchPoint]];[lineDic setObject:eraseArray forKey:@"eraseArray"];CGRect paintRect = CGRectMake(touchPoint.x-50, touchPoint.y-50, 100, 100);[self setNeedsDisplayInRect:paintRect];//[self setNeedsDisplay];continue;}}}}//[self eraseLine:currentLineDic erase:[thePan locationInView:self]];}else {if (thePan.state==UIGestureRecognizerStateBegan) {NSMutableArray *currentLineArray = [NSMutableArray arrayWithObject:[NSValue valueWithCGPoint:touchPoint]];NSMutableDictionary *lineDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:currentLineArray,@"line",_paintColor,@"color", nil];[linesArray addObject:lineDic];}else if(thePan.state==UIGestureRecognizerStateChanged){NSMutableDictionary *lineDic = [linesArray lastObject];NSMutableArray *currentLineArray = [lineDic objectForKey:@"line"];[currentLineArray addObject:[NSValue valueWithCGPoint:touchPoint]];CGRect paintRect = CGRectMake(touchPoint.x-50, touchPoint.y-50, 100, 100);[self setNeedsDisplayInRect:paintRect];}else if(thePan.state==UIGestureRecognizerStateEnded){}} } @end

?

?

demo下載地址:http://download.csdn.net/detail/donny_zhang/5572237


轉(zhuǎn)載于:https://www.cnblogs.com/snake-hand/archive/2013/06/13/3134585.html

總結(jié)

以上是生活随笔為你收集整理的ios 三种颜色画笔和橡皮擦的画图板demo的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 99热热久久 | 9.1成人看片 | 捆绑无遮挡打光屁股调教女仆 | a少妇| 北条麻妃99精品青青久久 | 精品人妻中文无码av在线 | 免费在线观看a级片 | 人人妻人人澡人人爽人人精品 | 成人另类小说 | 欧美女优一区 | 奇米精品一区二区三区在线观看一 | 一区二区不卡 | av免费福利| 久久久久久久国产精品毛片 | 亚洲欧美另类在线观看 | 91免费网站入口 | 丁香花婷婷 | 日韩精品伦理 | 国产欧美一区二区三区白浆喷水 | 日韩精品导航 | 亚洲天堂男人的天堂 | 久久久久久久穴 | 日美一级片 | 精品自拍视频在线观看 | 最新国产在线视频 | 欧美亚洲综合网 | 午夜影院免费观看 | 狠狠干天天干 | 日韩精品播放 | 久久免费在线观看 | 日本簧片在线观看 | 亚洲无码乱码精品国产 | 成年人毛片 | 国模少妇一区二区三区 | 99久草| 久久福利视频网 | 福利av在线 | 免费成人在线视频观看 | 一区二区视频播放 | 国产aa毛片 | 欧美一区二区三区黄片 | 国产精品理论片 | 国产精品高潮AV无码 | 在线观看无遮挡 | 操校花视频 | 精品欧美色视频网站在线观看 | 国产婷婷一区二区三区 | 熟女俱乐部一区二区视频在线 | 最近免费中文字幕中文高清百度 | 五月香婷婷 | 粉嫩精品久久99综合一区 | 欧美精品成人一区二区在线观看 | 亚洲色图导航 | 国产综合在线观看 | 色噜噜综合网 | 欧美中文字幕一区 | 亚洲欧美日韩在线播放 | 色月婷婷 | 美女视频国产 | 疯狂做爰的爽文多肉小说王爷 | 无码人妻精品一区二区中文 | 香蕉视频最新网址 | 亚洲性生活片 | 天天艹天天爽 | 快灬快灬一下爽69 | 亚洲三级欧美 | 欧美成人黄色 | 少妇久久久久久被弄高潮 | 动漫美女视频 | 在线视频 一区二区 | 日本一区成人 | 激情网五月天 | 亚洲成人日韩在线 | 香港三级在线视频 | 久久久久亚洲av无码a片 | 国产黄色www | 国产又粗又猛又爽又黄的视频一 | 在线视频亚洲色图 | 亚洲一区二区三区在线观看视频 | 久久久久午夜 | 亚洲图片一区二区 | 日日干夜| 欧美精品hd | 中文字幕第六页 | 一区二区三区av夏目彩春 | av小说免费在线观看 | 精品偷拍一区 | 91丨porny丨首页 | 欧美自拍偷拍第一页 | 我爱52av| 精产国品一二三区 | 性欧美ⅴideo另类hd | 日本精品一区二区三区四区 | 好吊妞视频这里只有精品 | 色一情一乱一区二区三区 | 男女插插视频 | 久久久青草 | 日韩视频一区二区在线观看 | 亚洲精品第三页 |