【发布时间】:2013-07-30 07:14:50
【问题描述】:
我在这个布局中使用自动布局:
self.view with frame (0,80, 320, 488)
带有框架的collectionView (0,0,320,220)
underView with frame (0,220,320,268)
并尝试实现一个动画,该动画应该调整 underView 的大小以扩大其高度,以便 underView 部分覆盖 collectionView 自下而上的移动。
Autolayout 为这两个视图强制设置高度约束,因此我为 underView 高度约束创建了一个 IBOutlet,我在动画中对其进行了调整:
NSLog(@"underView height %.2f", self.underView.frame.size.height);
NSLog(@"offset (%.2f, %.2f)", offset.x, offset.y);
heightConstraint.constant += offset.y;
NSLog(@"heightConstraint %.2f", heightConstraint.constant);
[self.underView setNeedsUpdateConstraints];
[UIView animateWithDuration:ANIMATION_DURATION
delay:ANIMATION_DELAY
options:UIViewAnimationOptionCurveEaseOut
animations:^{
[self.underView layoutIfNeeded];
NSLog(@"underView height %.2f", heightConstraint.constant);
} completion:nil];
在控制台中我可以看到:
2013-07-30 09:09:37.268 Cal[49611:a0b] underView height 268.00
2013-07-30 09:09:37.268 Cal[49611:a0b] offset (320.00, 144.00)
2013-07-30 09:09:37.269 Cal[49611:a0b] heightConstraint 412.00
2013-07-30 09:09:37.270 Cal[49611:a0b] underView height 412.00
但是根本没有调整大小。
我能想到的这种行为的唯一原因是上面collectionView的高度限制,但是由于我不希望重新加载集合,所以我无法对其进行操作。
我想知道如何实现让 underView 放大到 collectionView 之上?我尝试使用约束优先级,但没有奏效...
【问题讨论】:
标签: ios autolayout nslayoutconstraint