0

J'ai une application de contrôleur à vue unique. Il contient UIImageView et au toucher de l'utilisateur il dessine sur l'écran. Cette partie fonctionne bien. En vue did load méthode de viewcontroller j'ai mis en place une image différente comme image de fond. Et j'ai mis cet arrière-plan de vue d'image comme couleur claire. Maintenant, quand j'essaie d'effacer quelque chose de UIImageView, j'efface également la vue en arrière-plan du contrôleur de vue. Comment puis-je éviter ça ?Comment dessiner sur UIImageView sans affecter l'image de fond?

Voici mon code Pour définir un arrière-plan pour viewcontroller dans viewDidLoad()

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bacground.png"]]; 
image.backgroundColor = [UIColor clearColor];  

Pour dessiner à l'écran dans la méthode 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(); 

Pour effacer je suis en train juste drawcolor à whiteColor.

+1

double possible [Comment puis-je effacer les lignes UIBezierPath tracées sur une vue transparente au-dessus d'une image?] (http://stackoverflow.com/questions/7979937/how-can-i-erase-uibezierpath -lines-drawn-on-a-transparent-view-above-an-image) – jrturton

+0

wow ... Ça a marché comme un charme et jamais pensé de cette façon. Merci beaucoup pour le pointeur. – slonkar

Répondre

0

Pour définir l'image pour une utilisation de fond suivant et ensuite essayer de tirer l'autre image sur la vue

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

Essayez avec ci-dessus, je ne suis tombé sur ce problème jamais, mais je pense que cela fonctionnera pour vous. .et

background.userInteractionEnabled = YES; 
+0

Nope qui ne fonctionne pas – slonkar

Questions connexes