当内容加载时,我有一个带有UIActivityIndi​​catorView作为子视图的TableViewController,它的工作方式应该像它应该的那样。唯一的问题是我无法使活动指示器居中显示在屏幕上。

CGFloat width = CGRectGetWidth(self.view.bounds);
CGFloat height = CGRectGetHeight(self.view.bounds);

loadingIndicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(width / 2, height / 2, 125, 125)];
    loadingIndicator.center = CGPointMake(width / 2, height / 2);
    loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
    loadingIndicator.hidesWhenStopped = YES;
    [self.tableView addSubview:loadingIndicator];
    [loadingIndicator startAnimating];

最佳答案

可能是因为您的视图在xib中的尺寸错误(例如,在xib中iPhone 5的视图已在iPhone 6上运行)。
因此,您的高度和宽度计算是错误的。

而是尝试使用

CGFloat width = CGRectGetWidth(UIScreen.mainScreen.bounds);
CGFloat height = CGRectGetHeight(UIScreen.mainScreen.bounds);


希望能帮助到你 :)

关于ios - UIActivityIndi​​catorView未居中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29919901/

10-10 21:12
查看更多