2011-03-16 47 views
0

这是我的代码。我正在使用此代码来仅擦除imageView.image,但我也想擦除imageview子视图。我如何从imageView擦除子视图?如何从视图中删除子视图?

UIGraphicsBeginImageContext(imageView.frame.size); 
[imageView.image drawInRect:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height)]; 
CGContextSetLineCap(UIGraphicsGetCurrentContext(),kCGImageAlphaNone); //kCGImageAlphaPremultipliedLast); 
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10); 
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1, 0, 0, 10); 
CGContextBeginPath(UIGraphicsGetCurrentContext()); 
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), point.x, point.y); 
//this line code for erasing select the part of the image 
CGContextClearRect (UIGraphicsGetCurrentContext(), CGRectMake(point.x, point.y, 30, 30)); 
//End the code 
CGContextStrokePath(UIGraphicsGetCurrentContext()); 
imageView.image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

回答

1

您是否尝试过使用[imageView removeFromSuperview]

0

如果你想删除由于某种原因,所有的子视图,你可以尝试:

for (UIView *view in imageView.subviews) { 
    [view removeFromSuperview]; 
}