Search code examples
iosswiftrotationgestureuipangesturerecognizer

Swift How can I bring my Image after moving it back to the Middle ? Or rotate it back to the Origin position


I don't understand. how can I bring back my ImageView to the origin position (which is the Middle) of the view?

I want to use a TapGesture.

Or I have a second option to rotate it back to the original position. Currently I am trying to rotate it back but it doesn't work.

  @IBAction func backToOrigin(recognizer:UITapGestureRecognizer){
    if let view = recognizer.view{
    self.view.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi / 2))
    }
}

Solution

  • If you just want to undo a previous CGAffineTransform that you used to move or rotate your view you can use view.transform = CGAffineTransform.identity. (Also, delete the use of self from your code because self.view and the view inside your func are different things.)