I'm able to rotate UIView by 90 degree and also able to get rotation angle.
Need to implement--->reset myView rotation angle value to 0 but view position/direction should not go previous rotation/position value on UI and then if i rotate it has to start rotate from same position/direction and it's rotation angle need to start from 0.
I rotated view 90 degree by tapping on rotate button as below screen.
Here is the implementation code
@IBOutlet weak var myView: UIView!
@IBAction func rotateBtn(_ sender: Any) {
myView.transform = myView.transform.rotated(by: .pi/2)
getRotateAngles()
}
func getRotateAngles() {
let radians = atan2(myView.transform.b, myView.transform.a)
var degrees = radians * 180 / .pi
degrees.round()
let realDegrees = degrees >= 0 ? abs(degrees) : 360 + degrees
print("Degrees:: \(realDegrees)")
}
@IBAction func saveTapped(_ sender: Any) {
myView.transform = .identity //need to implement--->reset myView rotation angle value to 0 but view position/direction should not go previous rotation value on UI and then if i rotate it has to start rotate from same position/direction and it's rotation angle need to start from 0.
}
Here i can able to print view rotated degrees in 0, 90, 180, 270, 0.....
how can i able to reset view rotation value to 0 when save is tapped.
Coming to UI part if view is rotated 90 degrees and tapped on save view will be same on UI but the degrees value should start from 0.
if i keep transform identity myView is changing it's position on UI this is the issue. i don't want change it's place/position on UI but only view degrees should start from 0 when saveTapped.
FOR EXAMPLE: I rotated view it gives degrees 0, 90, 180, 270, 0... The requirement is i rotated view it prints degress 90. saveTapped then myView should be at same position/same place no change on UI. Now when i rotate again it has to print degrees 0, 90, 180, 270, 0....but in this case saveTapped and view is rotated 90 degree already
Thanks in advance.