简体   繁体   English

允许UIScrollView滚动过去的内容而不会反弹

[英]Allow UIScrollView to Scroll Past Content Without Bouncing

Overview 概观

I'm building an app the allows the user to overscroll the main UICollectionView by a certain amount in order to load related content. 我正在构建一个应用程序,允许用户将主UICollectionView一定量,以便加载相关内容。 The tactile experience of the overscroll should be the same as many other iOS apps that would cause the content on the current page to refresh, so I set collectionView.bounce = YES . 过度滚动的触觉体验应该与许多其他iOS应用程序一样,这些都会导致当前页面上的内容刷新,因此我设置了collectionView.bounce = YES

Once the user overscrolls by the designated amount, I want to move the current UICollectionView down and out of view, while simultaneously moving the new page down into view from the top of the device, very similar to the inter-article navigation in the Digg iPhone app. 一旦用户滚动超出指定数量,我想上下移动当前UICollectionView ,同时将新页面从设备顶部向下移动到视图中,这与Digg iPhone中的文章间导航非常相似应用程序。

I'm detecting the overscroll using this UIScrollViewDelegate method: 我正在使用以下UIScrollViewDelegate方法检测过度滚动:

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    CGFloat offsetY = scrollView.contentOffset.y;
    CGFloat contentHeight = scrollView.contentSize.height;

    if (offsetY < -40){
        [self.delegate overscrolledUp];
    }

    if (offsetY - (contentHeight - scrollView.frame.size.height) > 40){
        [self.delegate overscrolledDown];
    }
}

Problem 问题

The delegate takes care of moving the frames of these UICollectionView s, but my problem is that as the current page is moving down and out of view (or up and out of view if the user overscrolls down), the UICollectionView is also bouncing the scroll back to a contentOffset of (0,0). 委托负责移动这些UICollectionView的框架,但是我的问题是,随着当前页面上下移动(如果用户向下滚动,则上下移动), UICollectionView也将滚动滚动返回到(0,0)的contentOffset This results in a strange looking animation that I'd like to avoid. 我想避免这种奇怪的动画效果。 I want the user to be able to overscroll so an indicator is shown describing the new content they can see, but I don't want that overscroll to be reversed during the page-changing animation. 我希望用户能够过度滚动,以便显示一个指示器来描述他们可以看到的新内容,但是我不希望在换页动画期间反转过度滚动。

Question

Is there a way to prevent a UICollectionView / UIScrollView from returning its scroll to (0,0) after the user scrolls past the content? 有没有一种方法可以防止UICollectionView / UIScrollView在用户滚动经过内容之后将其滚动返回到(0,0)?

Take a look at 看一眼

https://github.com/enormego/EGOTableViewPullRefresh https://github.com/enormego/EGOTableViewPullRefresh

It contains a pull to refresh tableview code, you can use it directly or as a source of inspiration. 它包含刷新表格视图代码的功能,您可以直接使用它或将其用作灵感来源。

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

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