拖动后取消UIScrollView弹跳 [英] Cancel UIScrollView bounce after dragging

查看:495
本文介绍了拖动后取消UIScrollView弹跳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个水平的UIScrollView。我想做一个拉动 - 重置动画的变体,在那里我一直拉过滚动视图的内容大小的右边缘,释放我的手指,并让滚动视图飞回(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弹跳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆