简体   繁体   English

手指向下检测拖曳

[英]Detect drag with finger down

I've got a Scroll View with Paging View controller. 我有一个带有分页视图控制器的滚动视图。 The interface looks like this: 该界面如下所示:

@interface ScrollViewWithPagingViewController : UIViewController <UIScrollViewDelegate> {
    UIScrollView *scrollView;
    UIPageControl *pageControl;
    NSMutableArray *viewControllers;
}

and it lets me switch pages as expected when you do a swipe. 滑动后,可以让我按预期切换页面。

However, I'd like it to switch pages if you have one finger down and then do a swipe with a second finger which it currently doesn't do. 但是,如果您的一根手指向下滑动,然后我希望用第二根手指滑动,则我希望它可以切换页面,但目前尚不支持。 Not quite sure how to proceed though. 虽然不太确定如何进行。

  • Add a UIGestureRecogniser? 添加UIGestureRecogniser?

  • Subclass UIScrollView? 子类UIScrollView?

I would probably set a UIGestureRecognizer on the UIScrollView , specifically a UISwipeGestureRecognizer . 我可能会在UIScrollView上设置一个UIGestureRecognizer ,特别是UISwipeGestureRecognizer Then you would want to set the numberOfTouchesRequired property: 然后,您需要设置numberOfTouchesRequired属性:

swipeGesture.numberOfTouchesRequired = 2;

With any luck, this gesture will fire and allow you to cancel any other events (so that you don't scroll, or zoom, or...something else). 运气好的话,此手势将触发并允许您取消任何其他事件(这样就不会滚动,缩放或其他任何事情)。

Just as a hint, if I got you correctly what you are trying to do is a pinch right? 只是提示,如果我正确地理解了您,您要尝试的操作是正确的吗? Like when you zoom out on iphone. 就像您缩小iPhone一样。 If you keep a finger down and swipe the others in some direction is IMHO a pinch. 如果您不放过手指并朝某个方向滑动其他手指,恕我直言。 If that is the gesture you are trying to use you should look into UIGestureRecogniser and in particular into UIPinchGestureRecognizer (check http://bit.ly/f5sZMw ) (developer.apple.com link). 如果这是您要使用的手势,则应查看UIGestureRecogniser ,尤其是UIPinchGestureRecognizer (请检查http://bit.ly/f5sZMw)(developer.apple.com链接)。

-- Umberto -翁贝托

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM