滚动时,使UIScrollView中的UIView粘到顶部 [英] make UIView in UIScrollView stick to the top when scrolled up

查看:69
本文介绍了滚动时,使UIScrollView中的UIView粘到顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,在UITableView中,当您有截面时,截面视图会粘到顶部,直到下一部分与其重叠,然后将其替换为顶部。我希望有一个类似的效果,基本上我在UIScrollView中有一个UIView,表示UIView部分以及它何时触及顶部..我希望它留在那里而不是被占用。我该怎么做呢?我认为这需要在layoutSubviews或scrollViewDidScroll中完成并对UIVIew进行操作..

So in a UITableView when you have sections the section view sticks to the top until the next section overlaps it and then it replaces it on top. I want to have a similar effect, where basically I have a UIView in my UIScrollView, representing the sections UIView and when it hits the top.. I want it to stay in there and not get carried up. How do I do this? I think this needs to be done in either layoutSubviews or scrollViewDidScroll and do a manipulation on the UIVIew..

推荐答案

创建UIView in向上滚动时UIScrollView会粘到顶部:

To create UIView in UIScrollView stick to the top when scrolled up do:

- (void)createHeaderView:(UIView*)headerView {
    _headerView = [headerView retain];
    _headerViewInitialY = _headerView.frame.origin.y;
    [_scrollView addSubview:_headerView];
    _scrollView.delegate = self;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGRect headerFrame = _headerView.frame;
    headerFrame.origin.y = MAX(_headerViewInitialY, scrollView.contentOffset.y);
    _headerView.frame = headerFrame;
}

这篇关于滚动时,使UIScrollView中的UIView粘到顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆