0
votes

I have a UITableView that is a subview of my view controller. 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).

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.

Is there any way to isolate the layoutIfNeeded call to just the table view and not its subviews?

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: enter image description here

1

1 Answers

0
votes

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.

The solution was to remove the bottom layout constraint from the table view and instead give it an equal height constraint to the view.