//屏幕上有3个容器。顶部/中部/底部(我在这里只添加了中间代码)
- (void)initLayoutConstrains
{
[self initMiddleLayoutContainerConstraint];
NSMutableArray *constraints = [[NSMutableArray alloc] init];
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(_topContainerBar, _bottomContainerBar, _middleContainerBar);
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"|-(>=20)-[_middleContainerBar(==200)]-(>=20)-|"
options: NSLayoutFormatAlignAllCenterX | NSLayoutFormatAlignAllCenterY
metrics:nil
views:viewsDictionary]];
答案 0 :(得分:0)
编辑:我没有太多时间,但这是我提出的临时解决方案:
CGFloat testViewHeight = 200;
NSDictionary *metrics = @{ @"testViewY": @(self.view.frame.size.height / 2 - testViewHeight / 2), @"testViewHeight":@(testViewHeight)};
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-testViewY-[testView(==testViewHeight)]"
options: kNilOptions
metrics:metrics
views:viewsDictionary]];
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[testView]|" options:kNilOptions metrics:nil views:viewsDictionary]];