我遇到了一些问题,如果您能给我一些建议,我将不胜感激。
基本上,我使用可视格式语言创建了一些约束,并使我的基础更加动态。我没有触及我对故事板的看法。
您可以将红色区域视为导航栏。
在示例视图中看起来像;
我的问题是;我想在某个 viewController 上隐藏我的 topView。
首先我创建了一个属性;
@property (strong, nonatomic) NSLayoutConstraint *constraintTabbarHeight;
但我意识到我不能用 VFL 设置我的NSLayoutConstraint属性。因为 VFL 是创建一个约束数组。
所以这是我的第一个问题;无论如何用 NSLayoutConstraint 属性来保持我的 VFL 约束?
无论如何,所以我决定使用constraintWithItem方法创建我的高度约束。
self.constraintTabbarHeight = [NSLayoutConstraint constraintWithItem:self.tabbarContainerView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:95];
其次,我在stackoverflow上搜索并找到了一种方法。我可以从任何我想要的 viewController 调用这个方法。
- (void)updateTabbarConstraintWith:(int) heightValue{
self.constraintTabbarHeight.constant = heighValue;
[UIView animateWithDuration:0.3
animations:^{
[self.view layoutIfNeeded];
}];
}
如果我设置 self.constraintTabbarHeight.constant = 0 ,一切都很好。我的 TopView (redArea) 正在消失,但 PlaceholderView 仍在同一位置。
我认为 [self.view layoutIfNeeded] 会更新我的占位符 View 并填满我的屏幕。
它看起来像这样;
我如何使它正确?
感谢您的回答。