为什么以下代码不能将活动指示器定位到其超级视图的中心:
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给出的链接上找到了它,所以我接受他/她的回答.