Cancel UIScrollView bounce after dragging(拖动后取消 UIScrollView 弹跳)
问题描述
我有一个水平的 UIScrollView.我想做一个pull-to-reset"动画的变体,我一直拉到滚动视图内容大小的右边缘,松开手指,让滚动视图飞回 (0, 0) 内容偏移量.
I have a horizontal UIScrollView. I want to do a variation of the "pull-to-reset" animation, where I pull all the way past the right edge of the scroll view's content size, release my finger, and have the scroll view fly back to (0, 0) content offset.
我的委托方法如下所示:
My delegate method looks like this:
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
//check if it exceeds a certain critical value
if (scrollView.contentOffset.x - (scrollView.contentSize.width - IMAGE_WIDTH) > 80) {
[self doAnimatedScrollTo:CGPointMake(0, 0)];
}
}
其中 doAnimatedScrollTo:
是一个必要的自定义动画方法,因为我想控制动画的持续时间.
where doAnimatedScrollTo:
is a custom animation method necessary because I want to control the duration of the animation.
虽然这有效,但动画似乎已排队.UIScrollView反弹"动画首先发生,然后我的动画发生.
While this works, it seems that the animation is queued up. The UIScrollView "bounce" animation happens first, then my animation occurs.
有没有办法取消反弹动画,保持内容偏移从捕捉"回来,然后执行我的动画?
Is there a way to cancel the bounce animation, keep the content offset from "snapping" back, and then perform my animation?
推荐答案
试试这个
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
//check if it exceeds a certain critical value
if (scrollView.contentOffset.x - (scrollView.contentSize.width - IMAGE_WIDTH) > 80) {
[scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
}
}
这篇关于拖动后取消 UIScrollView 弹跳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:拖动后取消 UIScrollView 弹跳
基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01