This is my first time posting something, first of all you got to know two things, I’m very rookie on objective-c and english is not my native language, so if you don’t understand well please ask 🙂
Ok, I’m making an iPad app for my kid, so it consists of random sound and a random image on every tap. But after some taps the screen gets full of images so I want to know how to “clean” the screen after X taps.
Some code here:
- (void)oneFingerOneTap{
int randomNumber = arc4random() % 9 + 1;
int randX = arc4random() % 768 + 1;
int randY = arc4random() % 1004 + 1;
NSString *fileName = @"Sound";
NSString *ext = @".caf";
NSString *randString = [NSString stringWithFormat:@"%d", randomNumber];
NSString *completeSound = [NSString stringWithFormat:@"/%@%@%@", fileName, randString, ext];
NSString *path = [NSString stringWithFormat:@"%@%@", [[NSBundle mainBundle] resourcePath], completeSound];
SystemSoundID soundID;
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);
self.imgView = [[UIImageView alloc] initWithFrame:CGRectMake(randX, randY, 60, 60)];
self.imgView.image = [UIImage imageNamed:@"background.jpg"];
[self.view addSubview:self.imgView];
NSLog(@" %d", randX);
count++;
}
So I make a global int (count) to know how much taps done yet.
ps. I know the image isn’t random at the time, it doesn’t matter right now.
Again, how can I delete all the images done before?
I tried with self.imgView.hidden = TRUE; but it only hidden the last image.
try this code