title: How to reverse movement of a UIView?
body: <p>I have a uiview that is stacked on top of another uiview that slides back and forth on the left side. How can I reverse the it, to have it slide on the right side? Here is the code that I am using:</p>
  
  <pre><code>//Slides Left
  - (IBAction) panLayer:(UIPanGestureRecognizer *)pan {
  
      if (pan.state == UIGestureRecognizerStateChanged) {
  
          CGPoint point = [pan translationInView:self.topLayer];
          CGRect frame = self.topLayer.frame;
          frame.origin.x = self.layerPosition +point.x;
          if (frame.origin.x &lt; 0) frame.origin.x = 0;
          self.topLayer.frame = frame;
  
      }
  
      if (pan.state ==UIGestureRecognizerStateEnded) {
          if (self.topLayer.frame.origin.x &lt;= 160) {
              [self animateLayerToPoint:0];
  
          } else {
              [self animateLayerToPoint:VIEW_HIDDEN];
          }
  
      }
  
  }
  // Slides right
  - (IBAction)panLayerRight:(UIPanGestureRecognizer *)pan2
  {
      if(pan2.state == UIGestureRecognizerStateChanged)
      {
          CGPoint point = [pan2 translationInView:topLayer];
          CGRect frame = topLayer.frame;
          frame.origin.x = layerPosition + point.x;
          if(frame.origin.x + 320 &gt; 320) frame.origin.x = 0;
          topLayer.frame = frame;
      }
  
      if (pan2.state == UIGestureRecognizerStateEnded) {
          if (topLayer.frame.origin.x +320 &lt;= 260) {
              [self animateLayerToPoint2:-180];
          }
          else
          {
              [self animateLayerToPoint2:VIEW_HIDDEN];
          }
      }
  }
  
  -(void) animateLayerToPoint:(CGFloat)x
  {
      [UIView animateWithDuration:0.3
                            delay:0
                          options:UIViewAnimationCurveEaseOut
                       animations:^{
                           CGRect frame = self.topLayer.frame;
                           frame.origin.x = x;
                           self.topLayer.frame = frame;
                       }
                       completion:^(BOOL finished){
                           self.layerPosition = self.topLayer.frame.origin.x;
                       }];
  
  }
  
  -(void)animateLayerToPoint2:(CGFloat)x
  {
      [UIView animateWithDuration:0.3
                            delay:0
                          options:UIViewAnimationOptionCurveEaseOut
                       animations:^{
                           CGRect frame = topLayer.frame;
                           frame.origin.x = x;
                           topLayer.frame = frame;
                       }completion:^(BOOL finished) {
                           self.layerPosition = topLayer.frame.origin.x;
                       }];
  }
  </code></pre>