gpt4 book ai didi

ios - 当放置在固定大小的 UIView 下方时使用自动布局调整 UIView 的大小

转载 作者:行者123 更新时间:2023-11-29 10:56:46 26 4
gpt4 key购买 nike

我在这个布局中使用自动布局:

enter image description here

self.view with frame (0,80, 320, 488)

带框架的collectionView (0,0,320,220)

underView with frame (0,220,320,268)

并尝试实现一个动画,该动画应调整 underView 的大小并扩大其高度,以便 underView 部分覆盖自下而上移动的 collectionView。

Autolayout 为这 2 个 View 强制设置了高度约束,因此我为 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 之上?我尝试使用约束优先级,但它没有用......

最佳答案

根据 this answer 尝试以下操作.确保在父 View 上调用 layoutIfNeeded:

[UIView animateWithDuration:ANIMATION_DURATION
delay:ANIMATION_DELAY
options:UIViewAnimationOptionCurveEaseOut
animations:^{

heightConstraint.constant += offset.y;
[self.view layoutIfNeeded];

}
completion:nil];

关于ios - 当放置在固定大小的 UIView 下方时使用自动布局调整 UIView 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17940569/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com