Benches iPhone

13

Landscape Orientation with Utility Template

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

I haven't been able to make a well-behaved application that supports both portrait and landscape orientation when I use the Utility template. To reproduce the problem:

1) Open a new Xcode project and select the Utility Application template;
2) In RootViewController.m, change shouldAutorotateToInterfaceOrientation: to {return YES;}
3) Build and Go for the Simulator or the Device with either OS 2.0 or 2.1;
4) Rotate 90 degrees until the main view switches to landscape;
5) Touch the i control. At this point my flipside view is in landscape but the right third of the window is white;
6) Rotate -90 degrees until the flipside view switches to portrait. Except for the navigation bar, the right half of my window is now white;
7) Touch Done in the nav bar. When my main view returns in portrait the lower third of the window is white and the i control is gone.

When I add subviews (e.g. UIButton) to either the main view or the flipside view, controls (or the portion of the controls) in the white area are visible but don't respond.

Some similar behavior is described in Lower Half of Landscape Screen Unresponsive to Touch http://discussions.apple.com/thread.jspa?messageID=8235565&#8235565. A workaround is described in that post, but I don't think anyone has posted an explanation of the cause.

13 replies

Sign in or join Beachball Help to reply.

  1. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    My guess is because there are no +Autoresizing Behaviors+ set for the UINavigationBar in RootViewController.m. See the +iPhone OS Programming Guide+, and +View Controller Programming Guide for iPhone OS+.

    Message was edited by: xnav

  2. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Thanks for your reply, xnav. I added the following to loadFlipSideViewController:

    aNavigationBar.autoresizingMask = UIViewAutoresizingFlexibleWidth
    | UIViewAutoresizingFlexibleBottomMargin
    | UIViewAutoresizingFlexibleRightMargin;

    This did indeed result in a correctly sized nav bar when I switched to the flip side view while in portrait and then rotated to landscape. But when I follow the posted steps, switching to the flip side while in landscape etc., the behavior is the same.

  3. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Double click MainView.xib to get Interface Builder up, then highlight 'Main View' and go to the sizing Inspector window, it should be labled 'Main View Size' in Inspector and you should see a pulsing animation. Click to turn on both the horizontal and vertical springs within the small blue box. Only the left and top struts should be 'on'. Build and go and you should see better behavior.
    See +Interface Builder User Guide+ section on +Setting a View’s Autosizing Behavior+,

    Message was edited by: xnav

  4. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    The sizing springs for Main View are locked on and I think this is to be expected, since the view is intended to cover the entire window. I turned off the right and bottom struts, but this change made no difference in the behavior. I then also turned off the right and bottom struts for the Flipside View (the sizing springs are similarly locked). This change also made no difference (and again, I think this is to be expected for a full-window view, since there are no margins).

    I really don't think the behavior in question is an autosizing issue, since both the Main and Flipside views size correctly if all transitions are made during portrait orientation. The trouble begins when
    a transition is made during landscape.

  5. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Interesting, I made the changes in my sandbox and it worked.

  6. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Sorry, I am seeing the problem you describe depending when I rotate. I'll post back if I find a solution.

  7. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I don't think it can be done without significant modification, because of the way the two views are flipped. Both mainView and flipsideView are only loaded once and that is in portrait mode. Code needs to be added to toggleView to detect that the device is now in landscape and load a view that's compatible instead of just removing the flipped from and adding the original flipped to subview. Or, if the device is in landscape force the window back to portrait before adding the subview.

  8. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Thanks so much, xnav!! I'll try to restate your explanation to make sure I understand:

    When the root view changes to landscape, only it's current subviews will track the orientation change. E.g. if the switch to landscape occurs when ([flipsideView superview]==nil the flipside view is either not yet loaded or is in whatever orientation applied when it was last visible. We can only expect toggle to work correctly if the new subview's orientation matches the root orientation at that time, right?

    I guess one solution would be to add both main and flipside as subviews of root during initialization
    so that toggle could just change their visibility or order without ever removing either from the superview. But that would be wasteful in case of a memory warning, right? So the correct solution, as you said, would be to check the orientation of each view before it's added, then if necessary re-orient that view by hand. I assume I'd want the code given in IPhone OS Programming Guide "Launching in Landscape Mode" to go from portrait to landscape, and I'll need the inverse to go back the other way.

  9. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    You've got the idea, however, after playing with this a lot, I think you would be better off starting with the Tab Bar Application template. Just add a SecondViewController and a TabController class and the thing has basically the same appearance as the Utility template. I was able to get landscape/portrait switching to work perfectly by just using the IB struts and springs, and judicial placement of buttons, labels and subviews.

  10. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I just spent hours wrestling with this same problem. I want my main view to be landscape, and the flipside view to be portrait. I'll assume you know how to make the main view landscape in the first place.

    1) do NOT add autoresizing flags to the flipside view navigation bar
    2) keep the flipside view in portrait mode in interface builder
    3) select the flipside view in interface builder, and turn OFF all autosizing attributes.
    4) in RootViewController.m shouldAutorotateToInterfaceOrientation, return YES for both landscape modes if ([mainViewController.view superview] != nil), and return YES for portrait mode otherwise
    5) in RootViewController.m toggleView, add
    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
    at the end of the block where it checks if the mainview is null. Set the orientation to your preferred landscape orientation at the end of the "else" block.

    You do NOT need to modify shouldAutorotateToInterfaceOrientation in either the main view or flipside view controller - leave them commented out.

    For me, the key was turning off all autosizing in flipside view and flipside navigation bar.

  11. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    weird cut and paste error in my last post as it looks like the parser interprets the brackets as a URL or something. Anyway step 4 should check if the mainViewController.view's superview is nil in shouldAutorotateToInterfaceOrientation just as it does in toggleView. Make sense?

  12. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hey, thanks for the pointers, this is exactly what I am trying to do. The only problem that I am having implementing your solution is this line:
    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

    I get an warning that UIDevice may not respond to setOrientation, and in fact I can't find setOrientation in the UIDevice docs. Is that line compiling OK for you?

    thanks again for the post!

  13. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    That warning is harmless.