大佬教程收集整理的这篇文章主要介绍了ios – UIScrollView – 恢复到没有快照的起始位置,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVeLocity:(CGPoint)veLocity targetContentOffset:(CGPoint *)targetContentOffset { self.endingOffset = scrollView.contentOffset; if(abs(verticalOffset) > [self cellHeight] / 9) { // If the user scrolled enough distance,attempt to scroll to the next cell ... } else if(self.nextCellOrigin.y != 0) { // The scroll view is still scrolling and the user didn't drag enough ... } else { // If the user didn't drag enough self.tableView.decelerationRate = UIScrollViewDecelerationRateNormal; (*targetContentOffset) = self.starTingOffset; } }
恢复到原始位置的代码位于else部分,它始终有效.但是,当我不够滚动并快速做出手势时,它会快速向后移动.如果我稍微滚动一点,然后保持该位置比平时略长,它会平稳地恢复.
我没有在API参考中找到用户触摸UIScrollView多长时间的任何内容,即使我这样做也不是很明显我怎么能用它来改变我的还原代码的行为.我也尝试使用setContentOffset滚动到这个位置:动画:但这似乎并没有解决这个混蛋.
有任何想法吗?
编辑:
你可以尝试做的是实现这两个scrollView委托方法而不是willEndDragging方法.这个解决方案会给scrollView带来不同的感觉,但试一试.
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { // if scrollView's contentOffset reached its final position during scroll,it will not decelerate,so you need a check here too if (!deceleratE) { [self checkOffset]; } } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { [self checkOffset]; } - (void)checkOffset { CGPoint newOffset; ... // Do all the logic you need to move the content offset,then: ... [self.scrollView setContentOffset:newOffset animated:YES]; }
编辑#2:
如果您也将此添加到我的解决方案中,也许您可以获得更好的结果..尝试;)
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVeLocity:(CGPoint)veLocity targetContentOffset:(CGPoint *)targetContentOffset { // This should force the scrollView to stop its inertial deceleration,by forcing it to stop at the current content offset *targetContentOffset = scrollView.contentOffset; }
以上是大佬教程为你收集整理的ios – UIScrollView – 恢复到没有快照的起始位置全部内容,希望文章能够帮你解决ios – UIScrollView – 恢复到没有快照的起始位置所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。