相关疑难解决方法(0)

如何使用自动布局以编程方式将活动指示器定位到其超级视图的中心?

为什么以下代码不能将活动指示器定位到其超级视图的中心:

UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc]
       initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

[self.mysuperview addSubview:activityIndicator];
[activityIndicator addConstraints:[NSLayoutConstraint 
                   constraintsWithVisualFormat:@"|-(>=20)-[view(==100)]-(>=20)-|"
                   options:NSLayoutFormatAlignAllCenterX | NSLayoutFormatAlignAllCenterY
                   metrics:nil
                   views:@{@"view" : self.mysuperview}]];
Run Code Online (Sandbox Code Playgroud)

活动指示器位于左上角的某个位置,绝对不在中心位置.

==================更新:找到解决方案:我必须在创建指标后关闭自动调整约束,然后在给定工作的所有解决方案中关闭:

 [activityIndicator setTranslatesAutoresizingMaskIntoConstraints:NO];
Run Code Online (Sandbox Code Playgroud)

我在@Vignesh给出的链接上找到了它,所以我接受他/她的回答.

uiactivityindicatorview ios autolayout

19
推荐指数
3
解决办法
1万
查看次数

标签 统计

autolayout ×1

ios ×1

uiactivityindicatorview ×1