0

我有單個視圖控制器應用程序。它包含UIImageView,並在用戶觸摸時在屏幕上繪製。這部分工作正常。鑑於視圖控制器的負載方法,我設置了一個不同的圖像作爲背景圖像。我將該圖像視圖背景設置爲清晰的顏色。現在,當我嘗試從UIImageView中刪除某些東西時,我也刪除了視圖控制器背景視圖。我怎樣才能避免這種情況?如何在不影響背景圖像的情況下在UIImageView上繪圖?

這裏是我的代碼 要在viewDidLoad中設置的背景視圖 - 控制()

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。

+1

的可能重複的[上的圖像上方的透明視圖畫出如何能夠擦除UIBezierPath線?](http://stackoverflow.com/questions/7979937/how-can-i-erase-uibezierpath在上面的透明視圖上畫線) – jrturton

+0

哇......這就像一個魅力從來沒有這樣想過。非常感謝指針。 – slonkar

回答

0

要設置背景使用後的圖像,然後嘗試借鑑視圖

  UIImageView *background = [[UIImageView alloc]initWithImage:[UIImage imageNamed: @"backipad.png"]]; 
self.view = background; 

其它圖像上面試試,我還沒有碰到過這樣的問題就來了,但我認爲這會爲你工作。 。而

background.userInteractionEnabled = YES; 
+0

不行,不行 – slonkar

相關問題