0

touchesBegan メソッドで、両方が UIImageView である drawImage に stampBrush Image を追加しました

- (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をクリックして1つずつ削除しようとしています! drawImage からどのスタンプブラシを削除する必要がありますか!

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



}
4

2 に答える 2

1

スタンプを逆の順序で削除したいので、次のように UIImageView を拡張します。

YourImageView.h

@interface YourImageView : UIImageView {
    NSMutableArray *stamps;
}

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

@end

YourImageView.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 に答える
1
if([stampBrush superView])
{
    [stampBrush removeFromSuperView];
}
于 2012-05-25T07:32:55.543 に答える