已解决:检查以下问题的解决方案。
嘿,所以,
我无法将 UIActivityIndicator 置于视图中心。正如您在此处看到的,它垂直向下比应有的位置稍远。我拥有的是一个 UIScrollView,它后来添加了一个 UIImage 子视图。在 UIImage 加载之前,我有这个 UIActivityIndicator 来显示图像正在加载。
- (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 并将 UIActivityIndicator 设置在那里的任何想法?我不确定为什么self.view.center
不起作用。
提前致谢。
编辑:我必须考虑导航栏和标签栏的高度。我必须添加的代码是:
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);