Determine if UIImageView has been rotated

I rotate the UIImageView this way:

-(IBAction)rotateImageView:(id)sender{ photoView.transform = CGAffineTransformRotate(photoView.transform, M_PI); } 

As you can see, the image can be up or down. Is it possible to determine if the image is up or down to do something like this:

 if(image is up).... 
+8
ios objective-c
source share
2 answers

If you just want to determine if the image has been rotated using the affine transform, you think you can do this:

 if (CGAffineTransformIsIdentity(photoView.transform)) { // not rotated ... } else { // rotated ... } 

If you want to check for a specific rotation, do the following:

 CGAffineTransform t = CGAffineTransformMakeRotation(M_PI); if (CGAffineTransformEqualToTransform(photoView.transform, t)) { // rotated by M_PI ... } 

Note that the above two solutions only work if you do not apply OTHER affine transforms to the representation at the same time as the rotation transforms. If you also apply other transformations, perhaps you better just keep track of the state of rotation in the variable.

+10
source share

You can check the photoView angle if it is 0.00, which means it is up, and if it is 3 or 3.13 or any value close to it, then it shows that it is down. (you can write the exact value down).

CGFloat angle = [(NSNumber *)[photoView valueForKeyPath:@"layer.transform.rotation.z"] floatValue]; NSLog(@"%f", angle);

0
source share

All Articles