现象: IOS 中 UIActivityIndicatorView 和 andriod中ProgressDialog很类似,但是在iOS中 UIActivityIndiacatorView 是作为一个UIView存在,在显示的时候背景并没有发生任何变化。同时,我们也注意到 当调用 stopAnimation的时候UIActivityIndicatorView 会自己隐藏。
方法:
1.在需要弹出等待框的时候,首先添加一个背景并设置透明度,利用UIView的Tag进行唯一标识bgView
UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[bgView setTag:101];
[bgView setBackgroundColor:[UIColor blackColor]];
[bgView setAlpha:0.5];
[self.view addSubView:bgView];
loadingView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
[loadingView setCenter:self.view.center];
[loadingView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
[self.view addSubview:loadingView];
[loadingView startAnimating];
2.在需要结束等待框的时候,首先停止等待对话框,然后将背景对话框移出
[loadingView stopAnimating];
UIView *bgView = (UIView *)[self.view viewWithTag:101];
[bgView removeFromSuperview];