Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone/ipad orientation handling

This is more of a general question for people to provide me guidance on, basically Im learning iPad/iPhone development and have finally come across the multi-orientation support question.

I have looked up a fair amount of doco, and my book "Beginning iPhone 3 Development" has a nice chapter on it.

But my question is this, if I was to programatically change my controls (or even use different views for each orientation) how on earth to people maintain their code base? I can just imagine so many issues with spaghetti code/thousands of "if" checks all over the place, that it would drive me nuts to make one small change to the UI arrangement.

Does anyone have experience handling this issue? What is a nice way to control it?

Thanks a lot Mark

like image 940
Mark Avatar asked May 12 '10 02:05

Mark


People also ask

How do you control orientation on iPad?

Make sure that Rotation Lock is off: Swipe down from the top-right corner of your screen to open Control Center. Then tap the Rotation Lock button to make sure it's off.


1 Answers

I do this with two simple methods in my view controller:

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {     [self adjustViewsForOrientation:toInterfaceOrientation]; }  - (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {     if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {         titleImageView.center = CGPointMake(235.0f, 42.0f);         subtitleImageView.center = CGPointMake(355.0f, 70.0f);         ...     }     else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {         titleImageView.center = CGPointMake(160.0f, 52.0f);         subtitleImageView.center = CGPointMake(275.0f, 80.0f);         ...     } } 

To keep this clean you could easily compartmentalize the view adjustments/reloading/etc. with methods called from inside the single if-else conditional.

like image 56
Alex Reynolds Avatar answered Oct 04 '22 04:10

Alex Reynolds