由于弹跳无法获得正确的滚动视图方向

Can't get proper scrollview direction because of bounce

我正在尝试隐藏与滚动同步的元素。但是滚动弹跳效果弄乱了我的动画。

override func scrollViewDidScroll(scrollView: UIScrollView) {
        if (self.lastContentOffset > scrollView.contentOffset.y) {
            "Animate UIView up"
        }
        else if (self.lastContentOffset < scrollView.contentOffset.y){
            "Animate UIView down"
    }

有没有其他方法可以让我在不被弹跳弄乱的情况下获得我正在滚动的方向。我也不想禁用弹跳。

此外,由于我正在为与滚动同步的 uiview 设置动画,例如,我向上滚动 10px,然后 uiview 高度应最小化 10px,然后我需要 layoutifneeded() 或任何其他函数吗?

当它弹跳时,您可以假设它正在滚动 "out of bounds",您可以像这样检查它,并且只在视图没有超出范围时才为视图设置动画。

//Bouncing at the bottom
scrollView.contentOffset.y + scrollView.bounds.size.height > scrollView.contentSize.height;
// Bouncing at the top
scrollView.contentOffset.y < 0

如果 contentInset 属性 不同于 UIEdgeInsetZero

,您可能需要调整此代码