Objective c UIScrollView setContentInset在ios8中导致滚动跳过

Objective c UIScrollView setContentInset在ios8中导致滚动跳过,objective-c,uiscrollview,ios8,Objective C,Uiscrollview,Ios8,在scrollview底部创建拉入刷新机制时遇到问题。代码在iOS7中工作非常顺利,但在iOS8中,scrollview会在动画设置到正确位置之前立即跳转 我一直跟踪滚动条,直到它的橡皮筋超过kPullToRefreshHeightPX(在我的例子中是40px),并设置一个标志,然后在发布时插入,并触发内容刷新 - (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (_webShouldInsetScrollView ==

在scrollview底部创建拉入刷新机制时遇到问题。代码在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;
    }
}
如果在末端拖动时我们已经拖动到刷新距离之外,那么我们将插入(并运行我们的小刷新动画)并显示下一个结果页面

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

我在iOS8中阅读了UIScrollView的其他问题,其中一个问题谈到了在iOS7中将
automaticallyAdjustsScrollViewInsets设置为false,但现在在iOS8中默认为true,但这对上述代码没有影响。有没有其他人有过类似的经历并找到了解决办法?

在搜索了很长时间后,我找不到合适的答案。从github(在iOS8模拟器中运行)的几个pull-to-referesh实现来看,我可以看到所有这些在iOS8上显示完全相同的跳跃

下面是我能做的,以尽量减少这种影响。重述一下问题:当刷新控件需要保持可见时,我们试图通过superview
scrollView
中控件高度的值来调整
contentInset
。更改contentInset会触发滚动内容(在iOS7和iOS8上),在iOS8上,这种跳跃非常明显

我将contentInset中的任何更改从CustomPull to refres的基本
startRefresh
功能中删除。在您的情况下-从
ScrollViewDiEndDraging
中删除整个
UIView animateWithDuration:0.2动画

并将类似的内容添加到
scrollViewDidScroll
处理程序(开头):


我们有完全相同的问题

在深入挖掘之后,我发现,最初的目标插图设置在某个地方:

假设我将tableView从200下拉到500-在
ScrollViewDiEndDraging
上,我触发如下动画:

 [UIView animateWithDuration:0.2
                          delay:0
                        options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState
                     animations:^{
                         scrollView.contentInset = targetInset;
                     }
                     completion:nil];

    [self sendActionsForControlEvents:UIControlEventValueChanged];
在设置正确的动画值之前,将targetValue(250)设置一次,而不是从500平滑地设置回-250

我的解决方法是在开始动画之前设置动画标志。我在整个块中重置它。。。仅当动画结束时,滚动条才会检查此标志并设置targetValue:

_isAnimatingInset = YES;
_currentTopInsetTarget = targetInset.top;

 [UIView animateWithDuration:0.2
                          delay:0
                        options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState
                     animations:^{
                         scrollView.contentInset = targetInset;
                     }
                     completion:^(BOOL finished) {
                         //Workaround for a iOS8-Bug see property-comment for further infos
                         _isAnimatingInset = NO;
                         scrollView.contentInset = targetInset;
                     }];

    [self sendActionsForControlEvents:UIControlEventValueChanged];
这会将效果降至最低,但不幸的是,此时我无法阻止设置此错误值(而是将其重置为上一个值,这也会导致动画中出现小的hickUp…

修复该问题,:D

CGPoint offset = scrollView.contentOffset;
[scrollView setContentInset:UIEdgeInsetsMake(topInset, 0, 0, 0)];
scrollView.contentOffset = offset;

我看到了完全相同的事情。不过我还没找到解决办法。
CGPoint offset = scrollView.contentOffset;
[scrollView setContentInset:UIEdgeInsetsMake(topInset, 0, 0, 0)];
scrollView.contentOffset = offset;