检测scrollViewWillBeginDragging中UIScrollView滚动的方向 [英] Detect direction of UIScrollView scroll in scrollViewWillBeginDragging

查看:518
本文介绍了检测scrollViewWillBeginDragging中UIScrollView滚动的方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了足够的google,我确实检查过这样的帖子( iphone sdk:找到方向滚动在UIScrollView )在stackoverflow在发布之前。我在iPhone应用程序中有一张动态数量的照片,通过 UIScrollView 显示。在任何时间点,我只有3张照片显示在滚动视图中。当我有,总共4张照片:
第一张照片:显示在偏移0.0
第二张照片:显示在偏移320.0
第三张照片:显示在偏移640.0

I did google enough, & I did check posts like these ( iphone sdk: finding the direction of scrolling in UIScrollView ) in stackoverflow before posting this. I have a dynamic number of photos in an iPhone App, that am displaying through UIScrollView. At any point in time, I have only 3 photos being displayed in the scroll-view. When I have, say 4 photos, in total: 1st photo : displayed at offset 0.0 2nd photo : displayed at offset 320.0 3rd photo : displayed at offset 640.0

现在,当用户滚动到第4张照片时,滚动视图将重置为0.0偏移。如果用户试图滚动超出第四张照片,滚动应该只停止在右侧方向(所以用户不滚动超出)。但是目前,用户能够滚动到最后一张照片之外;然而,我检测这个程序和复位偏移。但它看起来不整洁,因为用户瞬间看到黑色背景。我想检测到用户已经开始在 scrollViewWillBeginDragging 中滚动'右'(记住,滚动'左',滚动到'上一张'照片是好的),

Now, when the user scrolls to the 4th photo, the scroll-view resets to 0.0 offset. If the user tries to scroll 'beyond' the 4th photo, scrolling should stop in the right-direction only (so that user doesn't scroll 'beyond'). But currently, the user 'is able' to scroll beyond the last photo ; however, I detect this programmatically & reset the offset. But it doesn't look neat, as the user sees the black background momentarily. I want to detect that the user has started scrolling 'right' (remember, scrolling 'left' i.e. to the 'previous' photo is okay) in scrollViewWillBeginDragging, so that I can stop any further scrolling to the right.

我尝试了以下操作:


  1. 使用 self.scrollView.panGestureRecognizer
    translationInView 无效,因为没有
    panGestureRecognizer 实例返回的第一个地方(!),
    通过UIScrollView API声明。

  2. 检测此在 scrollViewDidEndDecelerating 中是可能的,但
    不能用于我的目的。

  1. Trying using self.scrollView.panGestureRecognizer's translationInView isn't working, because there is no panGestureRecognizer instance returned in the first place (!), though the UIScrollView API claims so.
  2. Detecting this in scrollViewDidEndDecelerating is possible, though it'll not serve my purpose.


推荐答案

谢谢Kris。这是对我有用的,最后:

Thank you, Kris. This is what worked for me, finally:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    // Detect the scroll direction
    if (lastContentOffset < (int)scrollView.contentOffset.x) {
    ...
    }
}

这篇关于检测scrollViewWillBeginDragging中UIScrollView滚动的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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