2013-07-30 18 views
1

我使用自动布局与此布局下面调整大小的UIView与自动布局:当置于具有固定大小的UIView

enter image description here

与帧self.view(0,80,320,488)

的CollectionView与框架(0,0,320,220)

underView与框架(0220320268)

并试图实现这应该调整的动画underView放大其高度,使underView部分覆盖collectionView自下而上的移动。

自动布局强制的,因此我已经创建了一个IBOutlet为underView高度约束我在动画正在调整的2次的高度约束:

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的高度约束,但由于我不希望集合重新加载,我无法对此操作。

我想知道如何实现具有扩展OVER集合视图的underView?我尝试使用约束优先权,但它没有工作...

回答

0

所以,我发现了一个可能的解决我的问题,不知道这是否是最好的解决办法,但。我缺少self.collectionView的垂直空间约束的引用,所以最终的代码如下:

verticalSpace.constant -= shift; 
heightConstraint.constant += shift; 

[self.collectionView setNeedsUpdateConstraints]; 
[self.underView setNeedsUpdateConstraints]; 

[UIView animateWithDuration:ANIMATION_DURATION 
         delay:ANIMATION_DELAY 
        options:UIViewAnimationOptionCurveEaseOut 
       animations:^{ 
        [self.view layoutIfNeeded]; 
       } completion:nil 
]; 

我会等待其他更好的解决方案了一段时间,所以我不庆祝我自己的答案为接受了一个。

2

请尝试以下操作,根据this answer。确保你在上海华呼吁layoutIfNeeded

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

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

        } 
       completion:nil]; 
+0

谢谢@Maarten,但实际上这并没有什么区别,此外,如果您阅读了关于答案的注释,则链接人员已经确认,持续更新可以很好地避开动画,只留下layoutIfNeeded方法在动画块中。作为一个额外的提示,我也尝试调用[self.view layoutIfNeeded],因为有人指出是需要重新显示布局的超级视图,但没有再改变。 –

+0

你有没有试过在superView上调用'layoutIfNeeded'?我改变了我的答案以反映这一点。 – Maarten

+0

是的,正如我上面所说,self.view是superview。 –

相关问题