我在 viewDidLoad 中运行 2 个方法,在它们之间运行 NSRunLoop 10 秒
-(void)nextImage{ //charging a random image in the image view
index = [[NSArray alloc]initWithObjects:@"1.jpg",@"2.jpg",@"3.jpg",@"4.jpg",@"5.jpg",nil];
NSUInteger randomIndex = arc4random() % [index count];
NSString *imageName = [index objectAtIndex:randomIndex];
NSLog(@"%@",imageName);
self.banner=[UIImage imageNamed:imageName];
self.imageView.image=banner;
[imageName release];
}
-(void)horror{
self.banner=[UIImage imageNamed:@"Flo.jpg"];
self.imageView.image=banner;
NSString *path = [NSString stringWithFormat:@"%@%@",[[NSBundle mainBundle] resourcePath],@"/scream.wav"];
SystemSoundID soundID;
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);
}
- (void)viewDidLoad
{
[self nextImage];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:10.0]];
[self horror];
[super viewDidLoad];
}
这里图像没有改变,黑屏,10 秒后我只看到 [恐怖] 的结果。另一方面,当我在 viewDidLoad 中只保留 [nextImage] 图像更改时,我认为我的 NSRunLoop 出了点问题