0

我遇到了一些问题,如果您能给我一些建议,我将不胜感激。

基本上,我使用可视格式语言创建了一些约束,并使我的基础更加动态。我没有触及我对故事板的看法。

您可以将红色区域视为导航栏。

在示例视图中看起来像;

在此处输入图像描述

我的问题是;我想在某个 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 并填满我的屏幕。

它看起来像这样;

在此处输入图像描述

我如何使它正确?

感谢您的回答。

4

1 回答 1

0

您需要创建一个从 placeholderView.Top 到 TopView.Bottom 的约束,否则,一个将能够移动而不会影响另一个

于 2016-06-01T14:34:32.697 回答