繁体   English   中英

如何从另一个UIImageView中删除UIImageView

[英]How to remove UIImageView from another UIImageView

在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{



}
if([stampBrush superView])
{
    [stampBrush removeFromSuperView];
}

由于你想以相反的顺序删除标记,我会按如下方式扩展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]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM