gpt4 book ai didi

animation - 覆盖 scrollViewWillEndDragging 时,UIScrollView 并不总是动画减速

转载 作者:行者123 更新时间:2023-12-04 12:09:53 25 4
gpt4 key购买 nike

这是我的覆盖代码 - 它只是计算捕捉到的位置:

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {

if(targetContentOffset->y < 400) {
targetContentOffset->y = 0;
return;
}

int baseCheck = 400;

while(baseCheck <= 10000) {
if(targetContentOffset->y > baseCheck && targetContentOffset->y < baseCheck + 800) {
targetContentOffset->y = (baseCheck + 340);
return;
}
baseCheck += 800;
}

targetContentOffset->y = 0;
}

当我按住手指超过一两秒钟以拖动 ScrollView 然后抬起手指时,它通常会动画到位。但是,当我快速“轻弹”时,它很少有动画效果——它只是捕捉到 targetContentOffset。我正在尝试模拟默认分页行为(尝试捕捉到自定义位置除外)。

有任何想法吗?

最佳答案

我最终不得不手动为其设置动画。在同一个函数中,我将 targetContentOffset 设置为用户离开的位置(当前 contentOffset),这样它就不会触发它自己的动画,然后我将 contentoffset 设置为我的计算。此外,我添加了速度检查以触发“自动”页面更改。它并不完美,但希望它能帮助其他人解决同样的问题。

(我修改了上面的函数以提高可读性,因为没有人需要看到我的计算)

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {

CGPoint newOffset = CGPointMake(targetContentOffset->x, targetContentOffset->y);
*targetContentOffset = CGPointMake([broadsheetCollectionView contentOffset].x, [broadsheetCollectionView contentOffset].y);

if(velocity.y > 1.4) {
newOffset.y += pixelAmountThatWillMakeSurePageChanges;
}
if(velocity.y < -1.4) {
newOffset.y -= pixelAmountThatWillMakeSurePageChanges;
}

// calculate newoffset

newOffset.y = calculatedOffset;
[scrollView setContentOffset:newOffset animated:YES];
}

关于animation - 覆盖 scrollViewWillEndDragging 时,UIScrollView 并不总是动画减速,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15250173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com