Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

goldenlife

macrumors newbie
Original poster
Oct 2, 2010
24
0
HI ALL,

I want to draw transparent view on touch event, i.e I can erase section of the UIImageView so that I can see what is behind the UIImageView.

I am getting this but on touch, it erase the image in square shape,

I want this in round shape.

this is my code:

UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), YES);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
//CGContextSetLineCap(UIGraphicsGetCurrentContext(),kCGImageAlphaNone);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 15);

CGContextSetAlpha(UIGraphicsGetCurrentContext(), 0);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeNormal);// kCGBlendModeClear);
CGContextSaveGState(UIGraphicsGetCurrentContext()); //Probably right here


CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(),
lastPoint.x,
lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(),
currentPoint.x,
currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());


CGContextClearRect (UIGraphicsGetCurrentContext(), CGRectMake(lastPoint.x, lastPoint.y, 20, 20));
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();

//
This code works fine but it erase front Image in Square shape,
How can I make it in round shape?
can anybody help please?

Thanks.
 
I think you need to look at clipping for the context. See Clipping to a Path in the Quartz 2D Programming guide.
 
Hi,

thanks for your reply,
can you please elaborate on this , how to use clipping context here,
as I tried using clipping context, but still I am not getting round shape touch..

what kind of change I do in my code?

Please Help..
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.