简体   繁体   English

UITableView标头视图动画

[英]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. 我想复制在Kickstarter应用程序中发现的效果,其中,当用户向上滚动并且表格视图已经在开头时,标题视图的大小会增加。

To see the effect, just open a random project and scroll up. 要查看效果,只需打开一个随机项目并向上滚动即可。

Do you know how to achieve such animation? 你知道如何实现这种动画吗?

You can set delegate for you table view and use method scrollViewDidScroll:, UITableViewDelegate is sub-protocol of UIScrollViewDelegate, so you can just use: 您可以为表视图设置委托并使用方法scrollViewDidScroll:,UITableViewDelegate是UIScrollViewDelegate的子协议,因此您可以使用:

- (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);
    }
}

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

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