所以我们制作的游戏具有正常的UIView标题屏幕,当用户按下“开始游戏”按钮时,我们会尝试放置加载屏幕,删除标题视图,初始化游戏视图并添加它是超级视图(在我们的例子中为window
)在下方的加载屏幕。
不幸的是,最终结果是在触摸“开始游戏”按钮时UI被阻挡几秒钟,并且我们的加载屏幕在屏幕上闪烁一毫秒,然后开始加载游戏视图。我们甚至添加了日志记录,并且在阻止UI时,日志消息显示在控制台中。
以下是有问题的方法:
-(void)switchToGame{
NSLog(@"adding loading");
loadingScreen = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:@"loading_screen.jpg"]];
[self.window addSubview:loadingScreen];
NSLog(@"removing titlescreen");
[titleView.view removeFromSuperview];
self.titleView = nil;
if(self.gameView == nil){
gmViewController *g = [[gmViewController alloc]
initWithNibName:@"gmViewController"
bundle:nil];
self.gameView = g;
[gameView setIsLoading:YES];
self.gameView.parent = self;
[g release];
}
NSLog(@"inserting gameview");
[self.window insertSubview:gameView.view belowSubview:loadingScreen];
[self.window setRootViewController:gameView];
[self setGameIsActive:YES];
[gameView startAnimation];
//remove the loading screen
NSLog(@"killing loading");
[loadingScreen removeFromSuperview];
[loadingScreen release];
[gameView setIsLoading:NO];
}
答案 0 :(得分:0)
忘了这个问题。
我们通过移动加载屏幕添加它自己的功能来解决它:
- (void)addLoadingScreen
{
loadingScreen = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:@"loading_screen.jpg"]];
[self.window addSubview:loadingScreen];
}
然后在自己的线程上执行它:
[NSThread detachNewThreadSelector:@selector(addLoadingScreen)];