title: Converting Pan UIGesture to a Swipe Gesture
body: <p>When the user pans their finger over the specific cell, the cell changes color depending on the x-axis of the user. How would I go about changing from a pan gesture to a swipe. I would like to build it so that instead of panning, swiping on the cell reveals the color behind it. The cell should then snap back into place when the user lifts their finger. Any tips? </p>
  
  <pre><code>  @synthesize _panRecognizer;
  
  - (id)initWithReuseIdentifier:(NSString *)reuseIdentifier
   {
  if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier])
  {
      NSInteger emoteY = floor((self.frame.size.height - 32) / 2);
  
      _panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(respondToPanGesture:)];
      [_panRecognizer setDelegate:self];
      [_panRecognizer setMinimumNumberOfTouches:1];
      [_panRecognizer setMaximumNumberOfTouches:1];
      [self addGestureRecognizer:_panRecognizer];
  
   //        [[self textLabel] setFont:[UIFont boldSystemFontOfSize:18.0]];
      [[self textLabel] setFont:[UIFont systemFontOfSize:24.0]];
      [self setSelectionStyle:UITableViewCellSelectionStyleNone];
  
      _border = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, self.frame.size.height)];
      [self addSubview:_border];
  
      _rightEmote = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width - 42, emoteY, 32, 32)];
      [self addSubview:_rightEmote];
  
      _leftEmote = [[UIImageView alloc] initWithFrame:CGRectMake(-32, emoteY, 32, 32)];
      [self addSubview:_leftEmote];
  }
  
  return self;
  }
  
   - (void)setFrame:(CGRect)frame
   {
        [super setFrame:frame];
  
  CGRect borderFrame = _border.frame,
  rightEmoteFrame = _rightEmote.frame,
  leftEmoteFrame = _leftEmote.frame;
  
  NSInteger emoteY = floor((self.frame.size.height - 32) / 2);
  
  borderFrame.size.height = self.frame.size.height;
  rightEmoteFrame.origin.y = emoteY;
  leftEmoteFrame.origin.y = emoteY;
  
  [_border setFrame:borderFrame];
  [_rightEmote setFrame:rightEmoteFrame];
  [_leftEmote setFrame:leftEmoteFrame];
  }
  
   - (DDFactor *)factor
  {
      return _factor;
   }
  
   - (void)setFactor:(DDFactor *)factor
   {
  _factor = factor;
  </code></pre>
  
  <p>}</p>
  
  <pre><code>- (void)respondToPanGesture:(UIGestureRecognizer *)recognizer
   {
   //    NSLog(@"%lu", [recognizer state]);
  
  NSInteger rstate = [recognizer state];
  CGFloat touchX = 0.0;
  
  if ([recognizer numberOfTouches] == 1)
  {
      touchX = [recognizer locationOfTouch:0 inView:self].x;
  
      if (rstate == UIGestureRecognizerStateBegan)
      {
          /*
           animate to color under touch
           */
  
          CGRect labelFrame = [self textLabel].frame;
          labelFrame.origin.x += 42;
  
          CGRect rightEmoteFrame = _rightEmote.frame;
          rightEmoteFrame.origin.x += 42;
          CGRect leftEmoteFrame = _leftEmote.frame;
          leftEmoteFrame.origin.x += 42;
  
          [UIView animateWithDuration:0.3 animations:^{
              [_border setAlpha:0.0];
              [[self textLabel] setTextColor:[UIColor whiteColor]];
              [[self textLabel] setFrame:labelFrame];
              [_rightEmote setFrame:rightEmoteFrame];
              [_leftEmote setFrame:leftEmoteFrame];
          }];
          [self animateEmoticonsWithColor:NO duration:0.3];
      }
      else if (rstate == UIGestureRecognizerStateChanged)
      {
          /*
           alter color
           trigger emote animation if necessary
           */
  
          if ([self responseForTouchPosition:touchX] != _responseValue)
          {
              [self setResponseValue:[self responseForTouchPosition:touchX]];
              [_border setBackgroundColor:[UIColor colorForResponse:_responseValue]];
              [self animateToBackgroundColor:[UIColor colorForResponse:_responseValue]];
              [self animateEmoticonsWithColor:NO duration:0.2];
          }
      }
  }
  else if (([recognizer numberOfTouches] == 0) &amp;&amp; (rstate == 3))
  {
      CGRect labelFrame = [self textLabel].frame;
      labelFrame.origin.x -= 42;
  
      CGRect rightEmoteFrame = _rightEmote.frame;
      rightEmoteFrame.origin.x -= 42;
      CGRect leftEmoteFrame = _leftEmote.frame;
      leftEmoteFrame.origin.x -= 42;
  
      [UIView animateWithDuration:0.3 animations:^{
          [_border setAlpha:1.0];
          [_rightEmote setFrame:rightEmoteFrame];
          [_leftEmote setFrame:leftEmoteFrame];
          [[self textLabel] setFrame:labelFrame];
          [[self textLabel] setTextColor:[UIColor colorForResponse:_responseValue]];
          [self setBackgroundColor:[[UIColor colorForResponse:_responseValue] colorWithAlphaComponent:0.1]];
      }];
      [self animateEmoticonsWithColor:YES duration:0.3];
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code> - (void)setSelected:(BOOL)selected animated:(BOOL)animated
   {
  [super setSelected:selected animated:animated];
  
  // Configure the view for the selected state
   }
  
  - (DDResponseValue)responseForTouchPosition:(CGFloat)x
   {
  DDResponseValue response;
  
  if (x &lt;= 70) response = DDResponseGrin;
  else if (x &lt;= 120) response = DDResponseSmile;
  else if (x &lt;= 170) response = DDResponseSad;
  else if (x &lt;= 220) response = DDResponseNervous;
  else if (x &lt;= 270) response = DDResponseRefusal;
  else response = DDResponseNeutral;
  
  return response;
   }
  </code></pre>