Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do orientation rotation like built-in Calc app?

Tags:

iphone

I'm trying to make an app that handles orientation/rotation similarly to the way the built-in Calc app does.

If you check out that app, in portrait mode there's a normal calculator, and if you rotate to landscape mode there are additional buttons that appear to the left.

I can't figure out how to do this by setting the autosize masks. The problem is the "normal" calculator view is 320px wide in portrait mode, but actually shrinks to around 240px in landscape mode to fit the additional controls.

I've seen examples like the AlternateViews sample app that have two different view controllers (one for portrait and one for landscape), but they don't seem to animate the transitions between the views nicely like the Calc app does.

I've also tried setting the frames for the views manually in willAnimateSecondHalfOfRotationFromInterfaceOrientation, but it doesn't seem to look "quite right" and also I'm not certain how that works with the autoresize mask.

Any ideas how this is done? Thanks!

like image 464
Ray Wenderlich Avatar asked Nov 06 '22 13:11

Ray Wenderlich


1 Answers

Just override the following method call:

- (void)willRotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

Inside of there resize all of your components so they look nice.

like image 129
Pyro2927 Avatar answered Nov 15 '22 04:11

Pyro2927