Search code examples
iosuitableviewcore-animation

UITableView header view animation


I'd like to replicate the effect found in the Kickstarter app where, when the user scrolls up and the tableview is already at the beginning, the header view increases in size.

To see the effect, just open a random project and scroll up.

Do you know how to achieve such animation?


Solution

  • You can set delegate for you table view and use method scrollViewDidScroll:, UITableViewDelegate is sub-protocol of UIScrollViewDelegate, so you can just use:

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        if (scrollView.contentOffset.y < 0) {
            //you have to store image you want to scale somewhere (in ivar for example - _image)
            //k for scaling
            CGFloat k = fabs(scrollView.contentOffset.y)/10;
            _image.transform = CGAffineTransformMakeScale(k, k);
        }
    }