views:

454

answers:

3

THANKS FOR THE OVERWHELMING HELP HERE. I'VE JUST GIVEN THE BOUNTY TO THE CLOSEST ANSWER BECAUSE I WANT TO START A NEW BOUNTY, SO ONCE AGAIN THANKS IN ABSOLUTE TRUCKLOADS FOR THE TOP QUALITY HELP GIVEN HERE </sarc>

I have done what this question said here: http://stackoverflow.com/questions/2647786/landscape-mode-only-for-iphone-or-ipad

but the view.frame.size.height is still 1024, which is the height when the device is in portrait, surely when the interface rotates the width and height switch values?

(say you wanted to split the screen into 3 views, for an app that is both landscape and portrait, and you did view.frame.size.width / 3 , in landscape that wouldn't be correct as the width value wouldn't actually be the width)

I'm sure on the iPhone the width and height switch, so why not on the iPad?


This has struck me again I 'm not working with a nib either, could someone please give an acceptable answer? (ie one that doesn't involve manually switch the width and height)

Once the bounty has been awarded to an answer, I will then start another bounty for 250 and award it to the same person.

A: 

Can u provide some code? Usually, height and width are interchanged automatically when changing orientations, but that depends on a number of factors. Did you override the shouldAutorotateToInterfaceOrientation correctly? Did u set the required autoresizing flags on your víew?

Keep in mind that view.frame.size.height doesn't hold the old width value until didRotateFromInterfaceOrientation() has been called...

esdee84
A: 
+ (int) currentWidth
{
 UIScreen *screen = [UIScreen mainScreen];
 int width = screen.currentMode.size.width;
 int height = screen.currentMode.size.height;
 return (UIDeviceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))? MAX (width, height) : MIN (width, height);
}

I spent a while trying to work out the simplest solution to a frustrating problem, and this was the best I could come up with. Hope it can help.

maternaghan
So far, I can't do any better either. You'll get the bounty if no one does.
William Jockusch
+1  A: 

You haven't specified which "view" you're querying. Assuming this is the top level subview of the window:

You should query the view's bounds not its frame. frame is in the coordinate in which the view is defined (the outside world) hence may remain constant as you rotate. bounds is the coordinate used "inside" the view and for its subviews. This does change when you rotate.

Mo