这是我第一次发帖,首先你要知道两件事,我在objective-c上很菜鸟,而且英语不是我的母语,所以如果你不明白请问:)
好的,我正在为我的孩子制作一个 iPad 应用程序,所以它包含随机声音和每次点击时的随机图像。但是在点击几次后,屏幕上满是图像,所以我想知道在 X 次点击后如何“清理”屏幕。
这里有一些代码:
- (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++;
}
所以我做了一个全局int(计数)来知道已经完成了多少次点击。
附言。我知道当时图像不是随机的,现在没关系。
同样,我怎样才能删除之前完成的所有图像?
我试过了,self.imgView.hidden = TRUE;
但它只隐藏了最后一张图片。