[英]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.