2011-03-16 43 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]; 
}