【发布时间】:2018-01-04 08:49:33
【问题描述】:
我有两个代码块,一个有效,第二个无效。首先添加一个视图,将其高度限制为 0,然后在动画块中取消此约束,使其长大。完美运行。第二个应该重新激活0 height constraint,使其高度缩回到0,然后将其删除,但它会立即被删除。代码如下:
self.pickupAddressViewModel.infoViewBlock = ^(MandatoryPickupView * _Nonnull pickupView) {
if (weakSelf.mandatoryPickupView) {
return;
}
weakSelf.mandatoryPickupView = pickupView;
[weakSelf.view addSubview:pickupView];
CGFloat gap = weakSelf.orderButton.originY;
[[pickupView.bottomAnchor constraintEqualToAnchor:weakSelf.view.bottomAnchor constant:-gap] setActive:YES];
[[pickupView.leadingAnchor constraintEqualToAnchor:weakSelf.view.leadingAnchor
constant:16.0] setActive:YES];
[[pickupView.trailingAnchor constraintEqualToAnchor:weakSelf.view.trailingAnchor
constant:-16.0] setActive:YES];
weakSelf.mandatoryPickupViewHeight = [pickupView.heightAnchor constraintEqualToConstant:0];
[weakSelf.mandatoryPickupViewHeight setActive:YES];
[weakSelf.view layoutIfNeeded];
[UIView animateWithDuration:0.5 animations:^{
[weakSelf.mandatoryPickupViewHeight setActive:NO];
[weakSelf.view layoutIfNeeded];
}];
};
self.pickupAddressViewModel.closeViewBlock = ^{
if (!weakSelf.mandatoryPickupView) {
return;
}
[weakSelf.view layoutIfNeeded];
[UIView animateWithDuration:10.5
animations:^{
[weakSelf.mandatoryPickupViewHeight setActive:YES];
[weakSelf.view layoutIfNeeded];
} completion:^(BOOL finished) {
[weakSelf.mandatoryPickupView removeFromSuperview];
weakSelf.mandatoryPickupView = nil;
weakSelf.mandatoryPickupViewHeight = nil;
}];
};
- 这一切都发生在主线程上。
- 我尝试将框架的高度设置为 0,但也没有用
-
weakSelf.mandatoryPickupViewHeight是一个强大的属性,当我第二次激活时它不是 nil。
有什么建议吗?谢谢!
【问题讨论】:
-
mandatoryPickupViewHeight是强属性吗? -
是的,第二次激活时不为零
-
别叫这个
[weakSelf.view layoutIfNeeded];你可以像weakSelf.mandatoryPickupViewHeight.constant = 0一样调整大小 -
常量已经设置为0,我只是想重新激活常量。你必须调用 layoutIfNeeded
-
@MilanNosáľ 我做到了,这是使用遮罩层来圆角。在回答问题之前,我仍在试图弄清楚为什么会发生这种情况。感谢您的帮助
标签: ios animation constraints autolayout