如何使UIActivityIndi​​cator居中? [英] How to center UIActivityIndicator?

查看:87
本文介绍了如何使UIActivityIndi​​cator居中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已解决:请检查以下解决问题的方法。

SOLVED: Check below for the solution to my problem.

嘿嘿,

我无法集中UIActivityIndi​​cator在视图的中心。正如你在这里看到的那样,它在垂直方向上比它应该更远。我所拥有的是一个UIScrollView,后来添加了一个UIImage子视图。在加载UIImage之前,我有这个UIActivityIndi​​cator来显示图像正在加载。

I'm having trouble centering the UIActivityIndicator in the center of the view. As you can see here, it's a little farther down vertically than it should be. What I have is a UIScrollView that later adds a UIImage subview. Before the UIImage loads though, I have this UIActivityIndicator to show that the image is loading.

- (void)viewDidLoad
{

    [super viewDidLoad];
    self.scrollView.backgroundColor = [UIColor blackColor];
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]       initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    spinner.center = self.view.center;

    [spinner startAnimating];
    [self.view addSubview:spinner];

关于如何获得中心CGPoint并在那里设置UIActivityIndi​​cator的任何想法?我不知道为什么 self.view.center 不起作用。

Any ideas on how I could get the center CGPoint and set the UIActivityIndicator there? I'm not sure why self.view.center doesn't work.

提前致谢。

编辑:我必须考虑导航栏和标签栏的高度。我必须添加的代码是:

I had to account for the height of the navigation bar and the tab bar. The code I had to add was :

float navigationBarHeight = [[self.navigationController navigationBar] frame].size.height;
float tabBarHeight = [[[super tabBarController] tabBar] frame].size.height;
spinner.center = CGPointMake(self.view.frame.size.width / 2.0, (self.view.frame.size.height  - navigationBarHeight - tabBarHeight) / 2.0);

推荐答案

两个问题:


  1. 首先,self.view.center是当前视图框架在其父框架上的中心。如果你想要当前视图的中心,你想要 CGPointMake(self.view.frame.size.width / 2.0,self.view.frame.size.height / 2.0);

其次,您当前的视图不包含导航栏,因此您将其置于导航栏下方屏幕的空间中心。这也会让它看起来更低。

Second, your current view does not include the navigationbar, so you're centering it on the space of the screen below the nav bar. That will also make it look lower.

这篇关于如何使UIActivityIndi​​cator居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆