UIScrollView setContentInset导致ios8中的滚动跳过

Afo*_*fox 4 objective-c uiscrollview ios8

我在滚动视图底部创建一个拉动刷新机制时遇到问题.代码在iOS7中运行非常流畅,但在iOS8中,scrollview会立即跳过,然后动画到正确的位置.

我正在跟踪滚动,直到它有超出kPullToRefreshHeightPX的橡皮圈(在我的情况下这是40px),然后在释放时设置一个标志然后插入,并触发内容刷新.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (_webShouldInsetScrollView == NO && (scrollView.contentOffset.y > ((scrollView.contentSize.height - scrollView.frame.size.height) + kPullToRefreshHeightPX)))
    {
        _webShouldInsetScrollView = YES;
    }
}
Run Code Online (Sandbox Code Playgroud)

如果在结束时拖动我们已经超出了我们的刷新距离,那么我们插入(并运行我们的小刷新动画)并显示下一个结果页面.

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    if (_webShouldInsetScrollView)
    {
        [UIView animateWithDuration:0.2 animations:^{
                [scrollView setContentInset:UIEdgeInsetsMake(0.0f, 0.0f, kPullToRefreshHeightPX, 0.0f)];
        } completion:^(BOOL finished) {
        }];

        [self performSelector:@selector(showNextResultsPage) withObject:nil afterDelay:1.0f];
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经在iOS8中阅读了UIScrollViews的其他问题,其中一个讨论automaticallyAdjustsScrollViewInsets在iOS7中设置为false,但现在默认情况下在iOS8中是真的,但这对上面的代码没有影响.有没有其他人有类似的经历,并找到了解决方法?

小智 7

解决这个问题,:D

CGPoint offset = scrollView.contentOffset;
[scrollView setContentInset:UIEdgeInsetsMake(topInset, 0, 0, 0)];
scrollView.contentOffset = offset;
Run Code Online (Sandbox Code Playgroud)