最近写项目应为ip6 ip6+的原因 使用了autoLayout 而不是之前的autoResize
今天存在需求写剧中但是在vfl(visual Format language)中怎么都找不到方法。后来通过单独给子view与父view创建 constraint 来实现。代码如下
NSDictionary* views = NSDictionaryOfVariableBindings(_midView);
[_midView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[_midView(100)]" options:NSLayoutFormatAlignAllLeft metrics:nil views:views]];
[_midView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_midView(100)]" options:NSLayoutFormatAlignAllTop metrics:nil views:views]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_midView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_midView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
效果图