更改加载屏幕 UIActivity 指示器的方向

Posted

技术标签:

【中文标题】更改加载屏幕 UIActivity 指示器的方向【英文标题】:Changing orientation of loading screen UIActivity Indicator 【发布时间】: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); 【参考方案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);

希望这会有所帮助。

【讨论】:

以上是关于更改加载屏幕 UIActivity 指示器的方向的主要内容,如果未能解决你的问题,请参考以下文章

如何在移动方向更改时重置 Disqus 宽度

使用Blackberry JAVA SDK 6.0活动指示器UI元素加载屏幕轮

更改屏幕的滤色器以与多台显示器一起使用

苹果外接屏幕鼠标移动方向问题

如何修复视图居中之谜?

使用扩展屏时设置鼠标切换到另一屏幕的方向