Q: UIGestureRecognizer rotate UIVIew with CGAffineTransformRotate and with angle between zeroPoint(0, "some number") and gesture pan point I have a simple task: rotate UIView on user touch. Top of my view must always pointed on finger touch.
I tried to do it with next code:
func handlePan(recognizer: UIPanGestureRecognizer) {
        let currentPoint = recognizer.locationInView(self.superview)
        let dx = currentPoint.x - self.center.x
        let dy = currentPoint.y - self.center.y - self.radius
        let angle = atan2(dy, dx)
        var deg = angle * CGFloat(2.0 / M_PI)
        if deg < 0 {
            deg += 360.0
        }
        let transform = CGAffineTransformRotate(self.rotateView.transform, angle)
        self.rotateView.transform = transform
        println("x: \(currentPoint.x), y: \(currentPoint.y), angle: \(angle), deg: \(deg)")
    }

But I have a wrong angle as you can see below

x: 235.0, y: 426.5, angle: 0.616667, deg: 0.392582
x: 221.0, y: 431.5, angle: 0.761626, deg: 0.484866
x: 212.0, y: 433.5, angle: 0.858078, deg: 0.54627
x: 203.0, y: 436.5, angle: 0.973115, deg: 0.619504
x: 196.0, y: 437.5, angle: 1.05952, deg: 0.67451
x: 187.0, y: 439.5, angle: 1.18336, deg: 0.753351
x: 179.0, y: 439.5, angle: 1.29117, deg: 0.821982
x: 168.0, y: 439.5, angle: 1.45047, deg: 0.9234
x: 143.0, y: 439.5, angle: 1.82228, deg: 1.1601
x: 122.0, y: 437.5, angle: 2.10547, deg: 1.34038
x: 108.0, y: 435.5, angle: 2.26738, deg: 1.44346
x: 96.0, y: 429.5, angle: 2.42129, deg: 1.54144
x: 80.0, y: 423.5, angle: 2.5815, deg: 1.64343
x: 73.0, y: 418.5, angle: 2.66274, deg: 1.69515
x: 68.0, y: 415.5, angle: 2.71183, deg: 1.7264
x: 60.0, y: 409.5, angle: 2.79456, deg: 1.77907
x: 56.0, y: 406.5, angle: 2.83288, deg: 1.80347
x: 47.0, y: 397.5, angle: 2.9309, deg: 1.86587
x: 40.0, y: 384.0, angle: 3.05294, deg: 1.94356
x: 26.0, y: 359.0, angle: -3.03503, deg: 358.068
x: 18.0, y: 342.0, angle: -2.92442, deg: 358.138
x: 12.0, y: 326.0, angle: -2.83205, deg: 358.197
x: 8.0, y: 312.0, angle: -2.75807, deg: 358.244
x: 6.0, y: 303.0, angle: -2.71317, deg: 358.273
x: 5.0, y: 296.0, angle: -2.67881, deg: 358.295
x: 3.0, y: 286.0, angle: -2.63395, deg: 358.323
x: 2.0, y: 281.0, angle: -2.61273, deg: 358.337
x: 2.0, y: 277.0, angle: -2.59407, deg: 358.349
x: 2.0, y: 272.0, angle: -2.57132, deg: 358.363
x: 2.0, y: 269.0, angle: -2.55798, deg: 358.372
x: 3.0, y: 266.0, angle: -2.54192, deg: 358.382
x: 4.0, y: 264.0, angle: -2.53029, deg: 358.389
x: 6.0, y: 262.0, angle: -2.51563, deg: 358.398
x: 8.0, y: 260.0, angle: -2.5009, deg: 358.408
x: 11.0, y: 254.0, angle: -2.46631, deg: 358.43
x: 13.0, y: 250.0, angle: -2.44352, deg: 358.444
x: 16.0, y: 244.0, angle: -2.4098, deg: 358.466
x: 19.0, y: 238.0, angle: -2.3767, deg: 358.487
x: 24.0, y: 228.0, angle: -2.32303, deg: 358.521
x: 25.0, y: 222.0, angle: -2.29921, deg: 358.536
x: 28.0, y: 214.0, angle: -2.26265, deg: 358.56
x: 28.0, y: 206.0, angle: -2.2387, deg: 358.575
x: 29.0, y: 199.0, angle: -2.21521, deg: 358.59
x: 30.0, y: 191.0, angle: -2.19018, deg: 358.606
x: 31.0, y: 182.0, angle: -2.16401, deg: 358.622
x: 32.0, y: 174.0, angle: -2.14163, deg: 358.637
x: 34.0, y: 168.0, angle: -2.12118, deg: 358.65
x: 35.0, y: 161.0, angle: -2.10286, deg: 358.661
x: 36.0, y: 155.0, angle: -2.08731, deg: 358.671
x: 36.0, y: 152.0, angle: -2.08147, deg: 358.675
x: 37.0, y: 149.0, angle: -2.07233, deg: 358.681
x: 39.0, y: 146.0, angle: -2.05992, deg: 358.689
x: 39.0, y: 146.0, angle: -2.05992, deg: 358.689


And I don't know why my angle is always ~385.
Anyone have any idea what I do wrong?

A: Glancing at your code, it looks like you're converting from radians to degrees incorrectly.  360 degrees = 2π radians, so...
var deg = angle * CGFloat(180.0 / M_PI)

should fix things.
Hope this helps.
