views:

177

answers:

1

I've tried this:

CATransform3D rotationTransform = [[self.layer presentationLayer] transform];

This will not work, since the compiler will throw an warning and an error:

Warning: Multiple methods "-transform" found. Error: Invalid initializer.

So then I tried this:

CATransform3D rotationTransform = [[self.layer presentationLayer] valueForKey:@"transform"];

Error: Invalid initializer.

What's wrong with that?

+2  A: 

-presentationLayer returns an id. You need to cast it back to a CALayer:

CATransform3D rotationTransform = [(CALayer*)[self.layer presentationLayer] transform];

To be very safe, you would check first:

CATransform3D rotationTransform = {0};
id presentationLayer = [self.layer presentationLayer];
if( [presentationLayer respondsToSelector:@selector(transform)]) {
    CATransform3D = presentationLayer.transform;
}

But in practice, this is going to be fine without this check.

In the second case, -valueForKey: also returns an id, which you are trying to assign to struct, which is not possible to do implicitly. You can't just cast an object pointer into a struct.

Rob Napier
I also fixed that in the original answer which triggered this question: http://stackoverflow.com/questions/877198/is-there-a-way-to-figure-out-how-many-degrees-an-view-is-rotated-currently-durin/878618#878618 . He could have waited a little bit and I would have amended my answer, rather than asking a whole new question. However, this might be useful to keep as a standalone for people Googling something similar.
Brad Larson