I am rotating a UIImageView in this way:
-(IBAction)rotateImageView:(id)sender{
photoView.transform = CGAffineTransformRotate(photoView.transform, M_PI);
}
As you can see the image can either be up or down. Is there the possibility to detect if the image is up or down, in order to do something like this:
if(image is up)....
If you just want to tell if the image has been rotated using an affine transform, as your question implies, you can do this:
if (CGAffineTransformIsIdentity(photoView.transform)) {
// not rotated
...
} else {
// rotated
...
}
If you want to check for a particular rotation, do this:
CGAffineTransform t = CGAffineTransformMakeRotation(M_PI);
if (CGAffineTransformEqualToTransform(photoView.transform, t)) {
// rotated by M_PI
...
}
Note that the above two solutions only work if you are not applying OTHER affine transforms to the view at the same time as the rotation transforms. If you are also applying other transforms, perhaps you are better off just tracking the rotation state in a variable.
Swift 4
if transform.isIdentity { }
You can check the angle of the photoView
, if it is 0.00 that means its up and if its 3 or 3.13 or any close value to it then it shows that its down. (you can log the exact value of down).
CGFloat angle = [(NSNumber *)[photoView valueForKeyPath:@"layer.transform.rotation.z"] floatValue];
NSLog(@"%f", angle);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With