Code for Remove Layer (UIImageView) on Particular View

Hello Friends ,

below is code to remove with touch moved.

– (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

if(eraseOn == TRUE)
{
UITouch *touch = [touches anyObject];
lastTouch = [touch locationInView:self.drawImage];

}else{
/*
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
self.drawImage.center = location; */
}
}

– (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

if(eraseOn == TRUE){
UITouch *touch = [touches anyObject];
currentTouch = [touch locationInView:self.drawImage];
CGFloat brushSize = 5;
CGColorRef strokeColor = [UIColor whiteColor].CGColor;
UIGraphicsBeginImageContext(self.drawImage.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.drawImage.image drawInRect:CGRectMake(0, 0, self.drawImage.frame.size.width, self.drawImage.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);
self.drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastTouch = [touch locationInView:self.drawImage];
}
else {

// [self touchesBegan:touches withEvent:event];
}

}

– (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

}

And at below Link u can request for demo example ( how to integrate tutorial )

DrawView

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s