0

Ok the title might be vague but here is what I want to do.

My application has two wheels. User can rotate the outer wheel to match values in the inner wheel and thus displaying certain results according to the selected value.

Now I can rotate the image fine by setting the transform property. But once transformed, how would I know what is selected on the outer wheel??

One way would be to get the transform property and manipulate it.

But HOW???

atastrophic
  • 3,153
  • 3
  • 31
  • 50

2 Answers2

1

I would not rotate the image itself but the layer of the imageview. You can then always access the transform property of the layer of the imageview containing your image.

Ok, here is some code. First you have to get the layer of the uiimageview

CALayer* layer = [self.layer presentationLayer];

Then you can read the whatever rotation you need from the layers keypath like this.

float rotationAngle = [[layer valueForKeyPath:@"transform.rotation.z"] floatValue];

Let me know if this doesn't help. There is also an other way to obtain the rotation angle. But it is a bit more complex ;)

Maverick1st
  • 3,774
  • 2
  • 34
  • 50
  • I do rotate the `UIImageView`. A piece of code would help explaining the manipulation of `transform` property could help. – atastrophic Oct 23 '12 at 04:15
  • 1
    i edited my answer and added some sourcecode which might help you :) – Maverick1st Oct 23 '12 at 11:47
  • I'll try that and let you know. Here's my plan. Rotate the image on Iphone and log the rotation angle thus determining the range of `rotationAngle` value and map that range against the options on the outer wheel. Correct me if I am wrong =) – atastrophic Oct 23 '12 at 12:18
  • should work.What you planning to do always reminds me of the old copy protection from monkey island :) Wish you good luck :) – Maverick1st Oct 23 '12 at 13:19
0

You could keep track of how much you have rotated the image, in radians or degrees, as appropriate, and then do a bit of trig to figure out where it is pointing. It is surprisingly difficult to extract the rotation from an affine transform.

Edit: here are some untested snippets to get you started:

In your header:

CGFloat _userRotation;

When you apply your rotation, assuming rotation is a CGFloat, in radians, of the amount the user has rotated:

myView.transform = CGAffineTransformMakeRotation(rotation);
_userRotation = rotation;

Then, all you need to do is use a bit of trig to figure out which image you’re pointing at. I can’t give you sample code for that because the math depends on what you’re trying to do, but the current rotation will be available to you in _userRotation.

I’m not sure if that’s what you were asking. Does it help?

Zev Eisenberg
  • 8,080
  • 5
  • 38
  • 82