views:

541

answers:

1

I want to switch between a couple views with a flick gesture using two fingers. If anyone can tell me what I need to do please help.

+2  A: 

Without actually writing the code for you, here's what you'll need to do to track a multi-finger swipe:

  1. First, set your view's multipleTouchEnabled property to YES so that you'll be able to track multiple touches.
  2. In touchesBegan, store the each touches' locationInView property (this is a CGPoint).
  3. Define a "swipe window" that limits the amount of off-axis motion you'll accept and still consider the gesture a swipe. If, for instance, you're looking to track horizontal stripes, perhaps you'd want a "swipe window" of 12x6 -- that is, if your touches move at least 12 horizontal pixels while moving fewer than 6 vertical pixels, you'll consider it a swipe.
  4. In touchesMoved, compare the current location of the touches with the stored starting locations from step 2. If they're still in the "swipe window," do nothing. If one or both of the fingers has moved outside of its "swipe window," then cancel the swipe checking. If they've both met the requirements for a swipe, fire whatever method you want to have called when you've detected a multi-finger swipe.
  5. In 'touchesEnded', stop tracking the swipe, since if the touches have ended but you still haven't fired the swipe method from #4, then they must not have constituted a swipe.

Hope this helps.

John Biesnecker