【问题标题】:Changing orientation of loading screen UIActivity Indicator更改加载屏幕 UIActivity 指示器的方向
【发布时间】:2013-10-01 06:53:32
【问题描述】:

在我的 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];
}

如何更改代码以使视图根据设备的方向发生变化?

【问题讨论】:

  • 试试,activityIndi​​cator.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin);

标签: iphone ios loading


【解决方案1】:
 activityIndicator.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin); 

【讨论】:

    【解决方案2】:
    if (self.interfaceOrientation == UIInterfaceOrientationLandscape ||self.interfaceOrientation == UIInterfaceOrientationPortrait) {   
    yourctivity.view.frame = CGRectMake(self.view.center, self.view.center, 30, 30);
    }
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多