title: iOS - How to make objects draggable to only one direction at a time
body: <p>I'm trying to make an <code>UIViewImage</code>, and an <code>UILabel</code> draggable, and i having some problems to figure out how to make the Views, only draggable at one direction, for example, i want to drag  the views to left(x) or down(y), but never left and down at same time.</p>
  
  <p>I tried to use the <code>UISwipeGestureRecognizer</code>, to see in which direction i should move UP, DOWN or LEFT and RIGHT, but things are not working as i tough.</p>
  
  <p>To make things easier this is what a have on <code>viewController.h</code>:</p>
  
  <pre><code>///Images
  @property (nonatomic) UIImageView *mainImage; // Draggable Image
  @property (nonatomic) UISwipeGestureRecognizer *swipeDirection; // This will be used on TouchesMoved.
  
  //Label
  @property(nonatomic) UILabel *mainLabel; // Draggable Label
  </code></pre>
  
  <p>I'm adding the Swipe recognizer in the <code>viewDidLoad</code> Method, just for the Left (for now):</p>
  
  <pre><code> UISwipeGestureRecognizer *detectSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(setSwipe:)];
  [detectSwipe setDirection:UISwipeGestureRecognizerDirectionLeft];
      [self.view addGestureRecognizer:detectSwipe];
  </code></pre>
  
  <p>Here is where i set the "swipeDirection" property:</p>
  
  <pre><code>-(void)setSwipe:(UISwipeGestureRecognizer *)gesture {
      if (gesture.direction == UISwipeGestureRecognizerDirectionLeft) { // this is just for testing
      self.swipeDirection = gesture;
      NSLog(@"Gesture = %@", gesture);
      }
  
  
  }
  </code></pre>
  
  <p>Here is where I'm actually trying to move things (currently only to left):</p>
  
  <pre><code>-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
  
      for (UITouch *touch in touches ) {
          CGPoint currentLocalation = [touch locationInView:touch.view];
          if (self.swipeDirection.direction == UISwipeGestureRecognizerDirectionLeft) {
              NSLog(@"Swipe Left");
              if (currentLocalation.x &lt; startLocation.x) { // Startlocation is a global CGPoint.
                  NSLog(@"Current Y = %f, starting Y = %f", currentLocalation.y, startLocation.y);
  
                  CGFloat distance = startLocation.x - currentLocalation.x;
                  CGPoint newPosition = CGPointMake(160 - distance, 170);
                  CGPoint labelPosition = CGPointMake(160 - distance, 390);
                  self.mainImage.center = newPosition;
                  self.mainLabel.center = labelPosition;
  
              }
  
          } else {
              NSLog(@"Other direction");
          }
  
  }
  </code></pre>
  
  <p>What should i do? I'm looking at this from the wrong direction? Any help will be appreciated.</p>