在我的应用程序中,我正在从服务器接收数据。使用这些数据,我填充了一个表视图 (MasterViewController),当我选择该表中的一项时,它会在 DetailViewController 中显示详细信息。这些信息在应用程序每次启动或用户按下刷新按钮时加载。
在从服务器接收数据时,我想显示一个包含 UIActivityIndicatorView 和显示“正在加载...”的标签的视图。当我的应用程序以纵向模式启动或刷新时,这工作得很好。但是当我在横向模式下尝试相同时,我的视图大小不正确。
这是我用来加载视图的代码:
+ (SpinnerView *)loadSpinnerViewIntoView:(UIView *)superView {
SpinnerView *spinnerView = [[SpinnerView alloc] initWithFrame:superView.bounds];
if (!spinnerView)
return nil;
UIImageView *background = [[UIImageView alloc] initWithImage:[spinnerView addBackground]];
background.alpha = 0.7;
[spinnerView addSubview:background];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin;
indicator.center = superView.center;
[spinnerView addSubview:indicator];
[indicator startAnimating];
CGSize maximumLabelSize = CGSizeMake(296, 9999);
CGSize expectedLabelSize = [[NSString stringWithString:@"Loading..."] sizeWithFont:[UIFont boldSystemFontOfSize:25.0f] constrainedToSize:maximumLabelSize];
UILabel *loadingLbl = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, expectedLabelSize.width, expectedLabelSize.height)];
loadingLbl.text = @"Loading...";
loadingLbl.font = [UIFont boldSystemFontOfSize:25.0f];
loadingLbl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
loadingLbl.backgroundColor = [UIColor clearColor];
loadingLbl.textColor = [UIColor whiteColor];
loadingLbl.center = CGPointMake(superView.center.x, superView.center.y - indicator.frame.size.height - 25);
[spinnerView addSubview:loadingLbl];
[superView addSubview:spinnerView];
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionFade];
[[superView layer] addAnimation:animation forKey:@"layerAnimation"];
return spinnerView;
}
当我开始更新我的数据时,这是从我的 MasterViewController 调用的:
spinner = [SpinnerView loadSpinnerViewIntoView:self.splitViewController.view];
SpinnerView 在加载时获得与视图相同的边界。我真的不明白为什么它不能在横向模式下正确显示。我希望我的问题是可以理解的,任何人都可以帮助我。
提前致谢