在我的viewDidLoad
中,我调用了一个函数:
[common startActivityIndicatorOnView:self.view];
此方法添加一个带有 Activity 指示器的视图,位于self.view
. 我当前的视图被推送到导航堆栈上。这是该方法返回后视图的外观(活动指示器视图不在中心):
但是,如果我这样调用相同的方法:
[common performSelectorOnMainThread:@selector(startActivityIndicatorOnView:) withObject:self.view waitUntilDone:NO];
该视图如下图所示(活动指示器视图位于中心):
我不明白,如果调用行是用viewDidLoad
. 如果有人可以帮助我得到这个,在此先感谢。
仅供参考,该方法如下所示:
-(void) startActivityIndicatorOnView:(UIView *)view {
if ([NSRunLoop currentRunLoop] != [NSRunLoop mainRunLoop]) {
[self performSelectorOnMainThread:@selector(startActivityIndicatorOnView:) withObject:view waitUntilDone:NO];
return;
}
view.userInteractionEnabled = NO;
activityBgView = [[UIView alloc] initWithFrame:CGRectMake((view.frame.size.width/2) - 50, (view.frame.size.width/2) - 50, 100, 100)];
activityBgView.center = view.center;
activityBgView.backgroundColor = [UIColor grayColor];
activityBgView.alpha = 0.8;
spinner = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake((activityBgView.frame.size.width/2)-10, (activityBgView.frame.size.width/2)-10, 20, 20)];
spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
spinner.center = view.center;
[view addSubview:activityBgView];
[view addSubview:spinner];
[spinner startAnimating];
}