title: Draggable UIView Swift 3
body: <p>I want to be able to drag the objects on  the screen, but they wont. I tried everything but still cant.</p>
  
  <p>Here are the code.</p>
  
  <pre><code>func panGesture(gesture: UIPanGestureRecognizer) {
      switch gesture.state {
      case .began:
          print("Began.")
          for i in 0..&lt;forms.count {
              if forms[i].frame.contains(gesture.location(in: view)) {
                  gravity.removeItem(forms[i])
              }
          }
      case .changed:
          let translation = gesture.translation(in: forms[1])
  
          gesture.view!.center = CGPoint(x: gesture.view!.center.x + translation.x, y: gesture.view!.center.y + translation.y)
  
          gesture.setTranslation(CGPoint.zero, in: self.view)
  
          print("\(gesture.view!.center.x)=\(gesture.view!.center.y)")
          print("t;: \(translation)")
      case .ended:
          for i in 0..&lt;forms.count {
              if forms[i].frame.contains(gesture.location(in: view)) {
                  gravity.addItem(forms[i])
              }
          }
          print("Ended.")
      case .cancelled:
          print("Cancelled")
      default:
          print("Default")
      }
  }
  </code></pre>
  
  <p>Also they have gravity. The forms are squares and circles.</p>
  
  <p>Explanation:
  in .began - i disable the gravity for selected form.
  in .changed - i try to change the coordinates.
  in .end - i enable again gravity.</p>
  
  <p>ScreenShot.</p>
  
  <p><a href="https://i.stack.imgur.com/tWYsq.png" rel="noreferrer"><img src="https://i.stack.imgur.com/tWYsq.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/tomoJ.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/tomoJ.gif" alt="enter image description here"></a></p>