views:

199

answers:

3

I want to have a completely upside down interface. I don't mean it should change according to the orientation of the phone. I mean it should be upside down ( UIInterfaceOrientationPortraitUpsideDown ) the whole time. A button should be able to 'right' it again. The same button should return everything to upside down.

What's the best way of achieving this?

+1  A: 

Set the transform attribute on the root view's layer. Something like:

bool upsideDown = ...
float degrees = upsideDown ? 180.0f : 0.0f;
NSNumber* radians = [NSNumber numberWithFloat:degrees * M_PI / 180.0f];
[rootView.layer setValue:radians forKeyPath:@"transform.rotation.z"];

(Of course, you could easily optimize out the little formula converting from degrees to radians since you only use 0.0 and pi. Included it just for clarity.)

Felixyz
+1  A: 

If you want an upside-down interface, orientation does not matter. In essence, apply a rotated affine transform to the view you use, such as:

window.transform = CGAffineTransformRotate(window.transform, M_PI);

Some offset will be required there if you have a status bar up there. Apply that again and you "rotate" it back.

lukhnos