0

在 touchesBegan 方法中,我将 stampBrush Image 添加到 drawImage 中,两者都是 UIImageView

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

     stampBrush = [[UIImageView alloc] initWithImage:[[PaintColor stampImages] objectAtIndex:[stamp_Default integerForKey:STAMP_TYPE]]];

            [stampBrush setFrame:CGRectMake(lastPoint.x, lastPoint.y, stampBrush.image.size.width,stampBrush.image.size.height)];
            [drawImage addSubview:stampBrush];

}

现在我试图在 removeStampBrush 点击时一一删除!哪个 stampBrush 需要从 drawImage 中删除!

-(void)removeStampBrush:(UIButton *)sender{



}
4

2 回答 2

1
if([stampBrush superView])
{
    [stampBrush removeFromSuperView];
}
于 2012-05-25T07:32:55.543 回答
1

由于您想以相反的顺序删除图章,我将扩展 UIImageView 如下:

你的ImageView.h

@interface YourImageView : UIImageView {
    NSMutableArray *stamps;
}

- (void)addStamp:(UIImageView *)stamp;
- (void)removeLastStamp;

@end

你的ImageView.m

#import "YourImageView.h"

@implementation YourImageView

-(void)dealloc {
    [stamps release];

    [super dealloc];
}


- (void)addStamp:(UIImageView *)stamp {
    if (stamps == nil) {
        stamps = [[NSMutableArray array] retain];
    }

    [stamps addObject:stamp];
    [self addSubview:stamp];
}

- (void)removeLastStamp {
    if (stamps.count > 0) {
        UIImageView *stamp = [stamps lastObject];
        [stamp removeFromSuperview];

        [stamps removeLastObject];
    }
}

@end

现在从您的触摸事件调用[drawImage addStamp:stampBrush]中删除最后一个[drawImage removeLastStamp]

于 2012-05-25T19:05:23.413 回答