我有一个 uiimage 视图,如果我们触摸该透明层,则该透明层存在一个透明层,该透明层应该被擦除,并且应该显示其背面的图像..我该怎么做....?提前致谢
问问题
213 次
1 回答
0
据我了解,您想通过触摸来擦除图像的一部分……对吗?
尝试使用此代码通过触摸移动部分图像进行擦除....
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
lastTouch = [touch locationInView:canvasView];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
currentTouch = [touch locationInView:canvasView];
CGFloat brushSize = 35;
CGColorRef strokeColor = [UIColor whiteColor].CGColor;
UIGraphicsBeginImageContext(scratchView.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[canvasView.image drawInRect:CGRectMake(0, 0, canvasView.frame.size.width, canvasView.frame.size.height)];
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, brushSize);
CGContextSetStrokeColorWithColor(context, strokeColor);
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextBeginPath(context);
CGContextMoveToPoint(context, lastTouch.x, lastTouch.y);
CGContextAddLineToPoint(context, currentTouch.x, currentTouch.y);
CGContextStrokePath(context);
canvasView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastTouch = [touch locationInView:canvasView];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
}
我希望这能帮到您....
于 2012-09-08T13:55:04.690 回答