我有一个 PlayPageViewController 作为rootViewController
。 PlayPageViewController 将在方法调用 editPages()中显示3D模型和UIImages
,这将需要几秒钟等待。
我只想在开始时添加一个loadingView,当 PlayPageViewController 完全加载时,它将消失。
以下是我的解决方案:
但似乎无效
STLoadingViewController *loadingView =
[[STLoadingViewController alloc]initWithNibName:@"STLoadingViewController"
bundle:nil];
loadingView.view.frame=CGRectMake(0, 0, 1024, 768);
[self.view insertSubview:loadingView.view atIndex:3];
if(loadingView.isViewLoaded && loadingView.view.window)
{
[self.view insertSubview:self.playPageViewController.view atIndex:4];
[self.playPageViewController setEditingPage:pageIndex];
[loadingView.view removeFromSuperview];
}
答案 0 :(得分:1)
当调用此方法时,您必须使用viewDidAppear
方法调用所有出现的任务。
答案 1 :(得分:0)
ViewLoad()
方法是什么?你的意思是viewDidLoad:
?您可以在故事板中设置所有视图,包括包含活动指示器的视图。此时不要加载模型,而是等到调用viewDidLoad:
。此时,您可以使用Grand Central Dispatch开始加载模型。看起来有点像这样:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// You need to setup the activity indicator outlet in the storyboard
[_activityIndicator startAnimating];
}
- (void)viewDidLoad {
[super viewDidLoad];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
// Do the expensive work on the background
[NSThread sleepForTimeInterval:5.0f];
// All UI related operations must be performed on the main thread!
dispatch_async(dispatch_get_main_queue(), ^{\
// Replace the view containing the activity indicator with the view of your model.
[_activityIndicator stopAnimating];
NSLog(@"STOP");
});
});
}
编辑:链接似乎已关闭。这可能是由于开发中心目前存在的问题。您可以在Xcode Organizer的文档窗格中找到该文档。