具有垂直平移手势的水平滚动UIScrollView [英] Horizontal scrolling UIScrollView with vertical pan gesture

查看:131
本文介绍了具有垂直平移手势的水平滚动UIScrollView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现UIScrollView,其中水平平移可滚动浏览scrollview中的图片,但垂直平移则可以执行我的另一项操作.现在我有一个禁用了垂直滚动的UIScrollView,它可以很好地滚动图片,但是我疯狂地试图找到一种方法来拦截垂直平移并调用我自己的方法,而不是被垂直平移所吞噬滚动视图.我能够做到

I am attempting to implement a UIScrollView where horizontally panning scrolls through pictures in the scrollview but vertically panning performs another action I have. Right now I have a UIScrollView that is paginated with vertical scrolling disabled that works just fine for scrolling through pictures, but am going crazy trying to find a way to intercept vertical pans and call my own method instead of the vertical pans just being eaten up by the scrollview. I was able to do

    UIPanGestureRecognizer *panUp = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
[self.scrollView addGestureRecognizer:panUp];
[scrollView.panGestureRecognizer setEnabled:NO];

哪个可以让我完全控制handlePanGesture:方法中的平移,但这并不是特别有用,因为那样的话,我感觉我基本上将要重写所有试图避免的滚动逻辑.对于如何实现此目标的任何帮助或指导,将不胜感激.

Which gives me total control over the panning in my handlePanGesture: method, but this isn't particularly helpful because then I feel like I am essentially going to be rewriting all the scrolling logic which I am trying to avoid. Any help or guidance on how to achieve this would be greatly appreciated.

谢谢!

推荐答案

我认为如果您要使用平移手势会很困难,因为滚动视图使用了这些手势.但是,如果您可以使用滑动,则很容易实现.

I think this will be difficult if you want to use a pan gesture because of the scroll view's use of those gestures. However, if you could use a swipe, it is easy to implement.

    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
    swipe.direction = UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionUp;
    [self.scrollView addGestureRecognizer:swipe];

我对此进行了测试,并且可以很好地调用处理程序,并且您无需禁用滚动视图的平移手势识别器(在我的测试中,滚动视图足够高,内容足够短,因此没有垂直滚动-我不知道这是否有必要.

I tested this, and it worked fine to call the handler, and you don't need to disable the scroll view's pan gesture recognizer (in my test, the scroll view was tall enough and the content short enough that there was no vertical scrolling -- I don't know if this is necessary or not).

这篇关于具有垂直平移手势的水平滚动UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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