title: How to properly use swipeWithEvent to navigate a webView, Obj-C
body: <p>I want to implement the ability to navigate back and fourth in my webView by using the Event swipeWithEvent. However, I have no idea how I am suppose to use this. </p>
  
  <p>I have one main webView, and two methods that navigate back and fourth. A big problem here is that I'm not exactly sure how to write this question. I just need to know how to recognize swipe gestures on my webView and call my two methods. Similar to what Safari, Google Chrome, and Mozilla Firefox do. Thanks.</p>
  
  <p><strong>EDIT</strong>
  I have implemented these methods which are suppose to allow me to swipe back and forward.</p>
  
  <pre><code>- (void)swipeWithEvent:(NSEvent *)event {
      NSLog(@"Swipe With Event");
      CGFloat x = [event deltaX];
      //CGFloat y = [event deltaY];
  
      if (x != 0) {
          (x &gt; 0) ? [self goBack:self] : [self goForward:self];
      }
  }
  
  
  -(BOOL)recognizeTwoFingerGestures
  {
      NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
      return [defaults boolForKey:@"AppleEnableSwipeNavigateWithScrolls"];
  }
  
  - (void)beginGestureWithEvent:(NSEvent *)event
  {
      if (![self recognizeTwoFingerGestures])
          return;
  
      NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseAny inView:nil];
  
      self.twoFingersTouches = [[NSMutableDictionary alloc] init];
  
      for (NSTouch *touch in touches) {
          [twoFingersTouches setObject:touch forKey:touch.identity];
      }
  }
  
  - (void)endGestureWithEvent:(NSEvent *)event
  {
      if (!twoFingersTouches) return;
  
      NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseAny inView:nil];
  
      // release twoFingersTouches early
      NSMutableDictionary *beginTouches = [twoFingersTouches copy];
      self.twoFingersTouches = nil;
  
      NSMutableArray *magnitudes = [[NSMutableArray alloc] init];
  
      for (NSTouch *touch in touches)
      {
          NSTouch *beginTouch = [beginTouches objectForKey:touch.identity];
  
          if (!beginTouch) continue;
  
          float magnitude = touch.normalizedPosition.x - beginTouch.normalizedPosition.x;
          [magnitudes addObject:[NSNumber numberWithFloat:magnitude]];
      }
  
      // Need at least two points
      if ([magnitudes count] &lt; 2) return;
  
      float sum = 0;
  
      for (NSNumber *magnitude in magnitudes)
          sum += [magnitude floatValue];
  
      // Handle natural direction in Lion
      BOOL naturalDirectionEnabled = [[[NSUserDefaults standardUserDefaults] valueForKey:@"com.apple.swipescrolldirection"] boolValue];
  
      if (naturalDirectionEnabled)
          sum *= -1;
  
      // See if absolute sum is long enough to be considered a complete gesture
      float absoluteSum = fabsf(sum);
  
      if (absoluteSum &lt; kSwipeMinimumLength) return;
  
      // Handle the actual swipe
      if (sum &gt; 0)
      {
          [self goForward:self];
      } else
      {
          [self goBack:self];
      }
  
  
  }
  </code></pre>
  
  <p>However, this code isn't doing anything. It doesn't appear to be getting called at all.</p>