swift3 - One-finger wheel rotation in Swift 3 -


i'm making app in xcode 8.3 using swift 3 , i'm trying accomplish being able rotate wheel (uiimageview) using 1 finger.

i've done lot of research , found how that. however, run problems after first "spin". once done spinning wheel , want spin again, resets original position opposed rotating current position.

any fixing issue?

import uikit  class viewcontroller: uiviewcontroller {      var startpoint: cgpoint?      @iboutlet weak var wheel: uiimageview!       override func viewdidload() {         super.viewdidload()          self.wheel.isuserinteractionenabled = true     }      override func touchesmoved(_ touches: set<uitouch>, event: uievent?){         let touch = touches.first         if touch!.view === wheel {              let position = touch!.location(in: self.view)              let target = wheel.center              let angle1 = atan2(target.y-(startpoint?.y)!, target.x-(startpoint?.x)!)              let angle2 = atan2(target.y-position.y, target.x-position.x)              let angle3 = angle2-angle1              wheel.transform = cgaffinetransform(rotationangle: angle3)         }     }      override func touchesbegan(_ touches: set<uitouch>, event: uievent?) {         guard touches.count == 1 else {             return         }         if let touch = touches.first {             startpoint = touch.location(in: view)             //touchtime = nsdate()         }     }      override func didreceivememorywarning() {         super.didreceivememorywarning()         // dispose of resources can recreated.     } } 


Comments