title: How to rotate an UIImageView using TouchesMoved
body: <p>I am trying to rotate an <code>UIImageView</code> using Touch events, I want the image to rotate with my finger, I want to do the same as this: <a href="https://www.dropbox.com/s/cm61ak8rilyb09p/IMG_1420.MOV" rel="nofollow noreferrer">dropbox link</a> (best to see it, so u understand what I mean)</p>
  
  <p>After researching on how to rotate an UIImageView: <a href="https://stackoverflow.com/questions/852863/how-can-i-rotate-an-uiimageview-by-20-degrees">How can I rotate an UIImageView by 20 degrees</a>. I have tried the following code with my simple approach to developing iPhone apps:</p>
  
  <pre><code>class ViewController: UIViewController {
  
      var startpoint:CGPoint!
      var endpoint:CGPoint!
  
      @IBOutlet var yello:UIImageView
  
      override func touchesMoved(touches: NSSet!, withEvent event: UIEvent!) {
  
          let t:UITouch = touches.anyObject() as UITouch
          startpoint = t.locationInView(self.view)
          endpoint = t.previousLocationInView(self.view)
  
          if t.view == yello {
              var startX = startpoint.x
              var endX = endpoint.x
              yello.center = CGPointMake(yello.center.x, yello.center.y)
              UIView.animateWithDuration(1, animations: { self.yello.transform = CGAffineTransformMakeRotation(startX-endX)})
          }
      }
  }
  </code></pre>
  
  <p>I can see clearly that my code has a lot of mistakes and bad practices, and it also doesn't behave correctly as I want. (see dropbox link above)</p>
  
  <p>So maybe there is a better way to do this perhaps by using CoreAnimation, and I would appreciate if code sample would do the same as I want.</p>