简体   繁体   English

在UITableView上对layoutIfIf进行动画处理而无需对UITableViewCells进行动画处理

[英]Animating layoutIfNeeded on UITableView without animating UITableViewCells

I have a UITableView that is a subview of my view controller. 我有一个UITableView,它是我的视图控制器的子视图。 It sits on the bottom half of the screen and can be scrolled up using a gesture recognizer. 它位于屏幕的下半部分,可以使用手势识别器向上滚动。 When the gesture finishes, I call a UIView animation block to finish animating the UITableView by changing its top layout constraint (see example code below). 手势完成后,我将调用UIView动画块以通过更改其顶部布局约束来完成对UITableView的动画处理(请参见下面的示例代码)。

The animation itself works fine, but I noticed a strange side effect that the UITableViewCell subviews are exhibiting (check out the video - notice the bounce on the bottom-most cell of the table view), seemingly due to the layoutIfNeeded animation call. 动画本身可以正常工作,但是我注意到UITableViewCell子视图正在表现出一个奇怪的副作用(查看视频-注意表视图最底部单元格的反弹),这似乎是由于layoutIfNeeded动画调用所致。

Is there any way to isolate the layoutIfNeeded call to just the table view and not its subviews? 有什么方法可以将layoutIfNeeded调用仅隔离到表视图而不是其子视图吗?

Code: 码:

- (void) handlePanRecognizer:(UIPanGestureRecognizer*)recognizer {
  if (recognizer.state == UIGestureRecognizerStateEnded) {
    self.topLayoutConstraint.constant = 0.0f;

  //Animate
  [UIView animateWithDuration:kAnimationDuration
                        delay:0.0F
       usingSpringWithDamping:kAnimationBounce
        initialSpringVelocity:kAnimationBounce
                      options:UIViewAnimationOptionCurveEaseInOut
                   animations:^{
                     [self layoutIfNeeded];
                   } completion:^(BOOL finished) {
                   }];

  }
}

Video: 视频: 在此处输入图片说明

The problem ended up having to do with auto layout constraints. 问题最终与自动布局约束有关。

I had set a bottom constraint to my table view so its initialized height was much smaller than its full screen height. 我在表格视图中设置了底部约束,因此其初始化高度远小于其全屏高度。 When animating the top layout constraint, it would stretch the table view to the correct size, but auto layout was interpolating subview constraints (such as those in my table view cell contentView) weirdly. 在对顶部布局约束进行动画处理时,它会将表视图拉伸到正确的大小,但是自动布局却怪异地插入了子视图约束(例如我的表视图单元格contentView中的约束)。

The solution was to remove the bottom layout constraint from the table view and instead give it an equal height constraint to the view. 解决的办法是从表格视图中删除底部布局约束,然后为其赋予与视图相同的高度约束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM