如何从视图中删除子视图?

时间:2011-03-16 13:01:23

标签: iphone ios4

这是我的代码。我使用此代码仅擦除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();

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

如果您因某种原因尝试删除所有子视图,可以尝试:

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