我正在一個項目中產生圖像,你基本上觸摸它們,它們被刪除。我將如何移除我碰到的物體?我想過讓一個可變陣列來容納所有的物體,但我似乎無法找出任何東西。刪除觸摸的UIImageView
GameViewController.m
#import "GameViewController.h"
#import "Cig.h"
@interface GameViewController()
@end
@implementation GameViewController
@synthesize scoreLbl, timeLbl;
//CLASS ONLY VARS
BOOL isGameOver;
int timeInt;
int scoreInt;
int cigsOnScreen;
NSMutableArray *spawnedCigs;
//CLASS ONLY VARS
//TIMER
-(void)count {
timeInt--;
timeLbl.text = [NSString stringWithFormat:@"Time: %i", timeInt];
if(timeInt == 0){
isGameOver = YES;
NSLog(@"Your Score For This Round: %i", scoreInt);
}
if(isGameOver == NO){
[self performSelector:@selector(count) withObject:nil afterDelay:1];
}
}
//TIMER
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)spawnCigs {
for(int i =0 ; i < 5; i++){
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(arc4random()%760, arc4random()%430, 100, 23)];
UIImage *image = [UIImage imageNamed:@"Cig.png"];
[imageView setImage:image];
Cig *cig = [[Cig alloc] init];
[cig setTag:arc4random()%666];
[cig setImage:imageView];
[spawnedCigs addObject:cig];
[self.view addSubview:imageView];
}
[self performSelector:@selector(spawnCigs) withObject:nil afterDelay:5];
}
-(void)reset {
scoreLbl.text = @"Score:";
timeLbl.text = @"Time:";
isGameOver = NO;
timeInt = 60;
scoreInt = 0;
cigsOnScreen = 0;
spawnedCigs = [NSMutableArray arrayWithObjects:nil, nil];
[self performSelector:@selector(count) withObject:nil afterDelay:1];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self reset];
[self spawnCigs];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
代碼很凌亂,所以請不要評論我。
感謝您的提供
謝謝,我不完全理解這一點,但其他人確實幫助理解了這一點。我結合了2個答案來獲得我想要的結果,謝謝 – 2013-02-21 00:35:46