0

So, to handle orientation changes (in a view, not a controller) we register with the UIDeviceOrientationDidChange notification. All good.

It gets called on app startup, reporting the correct dimensions but incorrectly saying something changed (due to having landscape views or other software-reasons this may be triggered).

After the few unnecessary messages, it will start sending legitimate messages. The device will report the correct "to" orientation, but it will still give the current frame (and bounds), which is invalid.

To scroll the page to the right, other SO questions lead me to remember to manually set the contentOffset, which has most of what I need. currentPage = current Y offset / width of scrollview. Basic math, cool.

That fixed most of my problems. For proper OO, I gave the scroll view a relayout function, which isn't quite the size of the iPad since it's a subview, and in it I do this:

float currentDeviceWidth = 768;
float currentHeight = 949; //logging the frame from portrait, landscape = 1024 w, 693 h
UIDeviceOrientation o = [[UIDevice currentDevice] orientation];
if (!UIDeviceOrientationIsPortrait(o)) {
    //landscape
    currentDeviceWidth = 1024;
    currentHeight = 693;
}
else
    NSLog(@"Moving to port, unless on startup, then its staying as");

Which handles the orientationDidChange: messages, but when the app starts, the scroll view is now smaller than it should be because it set its size as if the bounds it's getting are "about to change", when they're not.

Possible solutions: a) [self performSelector:@selector(relayout) withObject:nil afterDelay:delayNum];

b) give a time delay before something like "BOOL dontIgnoreLayout" is set/unset

c) Find another way to test for orientation

d) manually go in and find out what's causing all the messages to be sent initially, remove all causes - this option is only possible if it's not created by the system on bootup. I can test this with a fresh project in a sec, though it's an enterprise app, may take some ripping if so.

Wondering if anyone solved this. If not, I have to put in "special case" or "time based" code, neither of which are OO style, at least not my preferred way (nor my coworkers).

If I missed something on SO, let me know, but as you can see, I have found a few answers thus far.

Thanks

Stephen J
  • 2,367
  • 2
  • 25
  • 31
  • http://stackoverflow.com/questions/5810397/status-bar-is-landscape-but-uiapplication-sharedapplication-statusbarorienta may have a workaround or so... will find out. Also, tested initial load thing, does get bogus messages on startup with fresh project – Stephen J May 15 '12 at 16:29

1 Answers1

0

I followed other people's examples by testing for Status Bar Orientation instead, it's seemingly always right, and shows conflicting messages with UIDevice currentOrientation... I know this has been found before, but the specific reason this fixed the problem is:

As per suggestions in other threads, I registered for notifications in ViewDidAppear and not viewDidLoad, this combination seems to be the win.

Stephen J
  • 2,367
  • 2
  • 25
  • 31