[英]How do I animate constraint changes if constraints are created programmatically with VFL?
我在某些事情上遇到麻烦,如果您能给我一些建议,我将不胜感激。
基本上,我使用Visual Format Language创建了一些约束,并使基础更加动态。 我没有触及情节提要上的观点。
您可以将红色区域视为navigationBar。
在示例视图看起来像;
我的问题是; 我想在某些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]将更新我的占位符视图,它会填满我的屏幕。
看起来像这样;
如何使它正确?
感谢您的回答。
您需要创建一个从placeholderView.Top到TopView.Bottom的约束,否则,一个约束将能够移动而不会影响其他约束
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.