【发布时间】:2011-11-11 10:06:21
【问题描述】:
我有单视图控制器应用程序。它包含 UIImageView 并在用户触摸时在屏幕上绘制。这部分工作正常。在视图中确实加载了视图控制器的方法,我设置了一个不同的图像作为背景图像。我将该图像视图背景设置为清晰的颜色。现在,当我尝试从 UIImageView 中删除某些内容时,我也会删除视图控制器背景视图。我怎样才能避免这种情况?
这是我的代码 在 viewDidLoad() 中为 viewcontroller 设置背景
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bacground.png"]];
image.backgroundColor = [UIColor clearColor];
使用 touchesMoved 方法在屏幕上绘图
UIGraphicsBeginImageContext(image.frame.size);
[image.image drawInRect:CGRectMake(0, 0, image.frame.size.width, image.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), lineWidth);
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), self.drawcolor.CGColor);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
image.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
要擦除,我只是将 drawcolor 设置为 whiteColor。
【问题讨论】:
-
哇...这就像一个魅力,从来没有那样想。非常感谢您的指点。
标签: iphone uiimageview core-graphics background-image background-color