在我的iPhone中我使用了加载屏幕(UIView中的活动指示器),现在我将我的应用程序转换为通用应用程序。所以我希望我的加载屏幕相对于设备的方向改变。我附上了代码
-(void) loading
{
waitingBGView = [[UIView alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 568.0)];
[waitingBGView setBackgroundColor:[UIColor blackColor]];
[waitingBGView setAlpha:0.5];
[appdelegate.window addSubview:waitingBGView];
smallBlackView = [[UIView alloc] initWithFrame:CGRectMake(([UIScreen mainScreen].bounds.size.width)/2 - 80, ([UIScreen mainScreen].bounds.size.height)/2 - 30, 160.0, 60.0)];
smallBlackView.layer.borderColor = [[UIColor whiteColor] CGColor];
smallBlackView.layer.borderWidth = 2.0;
smallBlackView.layer.cornerRadius = 7.0;
smallBlackView.backgroundColor = [UIColor blackColor];
activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[activityIndicator setFrame:CGRectMake(5.0, 5.0, 50.0, 50.0)];
[smallBlackView addSubview:activityIndicator];
[activityIndicator startAnimating];
UILabel *lblLoading = [[UILabel alloc]initWithFrame:CGRectMake(60.0, 0.0, 100.0, 60.0)];
lblLoading.backgroundColor = [UIColor clearColor];
lblLoading.font = [UIFont fontWithName:@"Helvetica" size:18.0];
lblLoading.textColor = [UIColor whiteColor];
lblLoading.text = @"Loading...";
[smallBlackView addSubview:lblLoading];
[appdelegate.window addSubview:smallBlackView];
}
如何更改代码以使视图相对于设备的方向发生变化?
答案 0 :(得分:0)
activityIndicator.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin);
答案 1 :(得分:0)
if (self.interfaceOrientation == UIInterfaceOrientationLandscape ||self.interfaceOrientation == UIInterfaceOrientationPortrait) {
yourctivity.view.frame = CGRectMake(self.view.center, self.view.center, 30, 30);
}
希望这会有所帮助。