在第一次启动时,该应用程序处理数据库的内务管理。这需要一段时间,因此,我添加了一个带有微调器的半透明视图和一个告诉用户发生了什么的标签。
为了将这个半透明视图置于其他所有内容之上,我已将其添加为 self.view.window 的子视图。整个代码如下所示:
-(void)housekeepDataBase{
self.searchOptionsControl.hidden=TRUE;
self.searchBar.hidden=TRUE;
UIView *translucentView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.window.frame.size.width, self.view.window.frame.size.height)];
translucentView.backgroundColor=[UIColor blackColor];
translucentView.alpha=0.65;
UILabel *activityLabel=[[UILabel alloc]initWithFrame:CGRectMake((self.view.center.x-140), (self.view.frame.size.width*0.75), 280, 20)];
activityLabel.numberOfLines=1;
activityLabel.textAlignment=UITextAlignmentCenter;
activityLabel.font=[UIFont fontWithName:@"Arial" size:20.0];
activityLabel.text=@"Cleaning up database";
activityLabel.textColor=[UIColor whiteColor];
activityLabel.backgroundColor=[UIColor clearColor];
UILabel *activityLabel2=[[UILabel alloc]initWithFrame:CGRectMake((self.view.center.x-140), (self.view.frame.size.width*0.75+40), 280, 20)]; activityLabel2.numberOfLines=1;
activityLabel2.textAlignment=UITextAlignmentCenter;
activityLabel2.font=[UIFont fontWithName:@"Arial" size:16.0];
activityLabel2.text=@"(It might take a while)";
activityLabel2.textColor=[UIColor whiteColor];
activityLabel2.backgroundColor=[UIColor clearColor];
UIActivityIndicatorView *spinner=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.frame=CGRectMake((self.view.center.x-50), (self.view.frame.size.width*0.50), 100, 37);
[spinner startAnimating];
[self.view.window addSubview:translucentView];
[self.view.window addSubview:spinner];
[self.view.window addSubview:activityLabel];
[self.view.window addSubview:activityLabel2];
// dealing with the DB
}
不幸的是,它会导致这些视图(视图、微调器和标签)不根据设备方向旋转。
所以,问题是:有没有其他方法可以处理这个问题?旋转或添加视图?我想要的是让半透明视图位于屏幕顶部的导航栏顶部,以及底部工具栏的顶部。
有任何想法吗?提前致谢!