谢谢
这是我到目前为止所做的:
- (voID)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UItouch *touch = [touches anyObject]; lastPoint = [touch locationInVIEw:self.vIEw];}- (voID)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ UItouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInVIEw:self.vIEw]; UIGraphicsBeginImageContext(self.vIEw.frame.size); [drawImage.image drawInRect:CGRectMake(0,self.vIEw.frame.size.wIDth,self.vIEw.frame.size.height)]; CGContextSetlineCap(UIGraphicsGetCurrentContext(),kCGlineCapRound); CGContextSetlinewidth(UIGraphicsGetCurrentContext(),10); CGContextBeginPath(UIGraphicsGetCurrentContext()); CGContextSetRGBstrokecolor(UIGraphicsGetCurrentContext(),0.0,1.0); CGContextMovetoPoint(UIGraphicsGetCurrentContext(),lastPoint.x,lastPoint.y); CGContextAddlinetoPoint(UIGraphicsGetCurrentContext(),currentPoint.x,currentPoint.y); CGContextstrokePath(UIGraphicsGetCurrentContext()); drawImage.image = UIGraphicsGetimageFromCurrentimageContext(); UIGraphicsEndImageContext(); lastPoint = currentPoint;}- (voID)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{UItouch *touch = [touches anyObject];CGPoint currentPoint = [touch locationInVIEw:self.vIEw];UIGraphicsBeginImageContext(self.vIEw.frame.size);[drawImage.image drawInRect:CGRectMake(0,self.vIEw.frame.size.height)];CGContextSetlineCap(UIGraphicsGetCurrentContext(),kCGlineCapRound);CGContextSetlinewidth(UIGraphicsGetCurrentContext(),10);CGContextBeginPath(UIGraphicsGetCurrentContext());CGContextSetRGBstrokecolor(UIGraphicsGetCurrentContext(),1.0);CGContextMovetoPoint(UIGraphicsGetCurrentContext(),lastPoint.y);CGContextAddlinetoPoint(UIGraphicsGetCurrentContext(),currentPoint.y);CGContextstrokePath(UIGraphicsGetCurrentContext());drawImage.image = UIGraphicsGetimageFromCurrentimageContext();UIGraphicsEndImageContext();lastPoint = currentPoint;}- (IBAction)clear:(ID)sender {drawImage.image = nil;}解决方法 好的,这就是我为橡皮擦工具所做的:
我添加这行代码:
CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeClear);
所以代码将是这样的东西:
- (voID)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{UItouch *touch = [touches anyObject];CGPoint currentPoint = [touch locationInVIEw:self.vIEw];UIGraphicsBeginImageContext(self.vIEw.frame.size);[drawImage.image drawInRect:CGRectMake(0,self.vIEw.frame.size.height)];// I add thisCGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeClear);CGContextSetlineCap(UIGraphicsGetCurrentContext(),sizeSlIDer.value);CGContextBeginPath(UIGraphicsGetCurrentContext());CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeClear);CGContextMovetoPoint(UIGraphicsGetCurrentContext(),currentPoint.y);CGContextstrokePath(UIGraphicsGetCurrentContext());drawImage.image = UIGraphicsGetimageFromCurrentimageContext();UIGraphicsEndImageContext();lastPoint = currentPoint;}总结
以上是内存溢出为你收集整理的在iOS中为paint应用程序制作橡皮擦工具全部内容,希望文章能够帮你解决在iOS中为paint应用程序制作橡皮擦工具所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)