views:

91

answers:

2

Hi, I'm trying to convert an iPhone app to iPad. The tricky things is that the iPhone app has to be locked to portrait view and the iPad app has to be locked to landscape view. I'm kind-of a noob at interface builder so I'm a little lost.

Any help is greatly appreciated. Thanks!

A: 

You should have two nibs and load them separately depending on which device your application determines it is running on: one for the iPad and one for the iPhone. You can then set the orientation easily. NB: The iPad app should support all orientations variants (ie. if you support portrait, support portrait upside-down) and will most likely get rejected by Apple unless you have a compelling reason as to why it shouldn't.

Felixs
While Apple definitely *encourages* all iPad apps to support all rotations, I disagree that it will "most likely get rejected" if it doesn't, mainly because I've submitted an iPad app that was fixed to portrait that didn't give "a *very* compelling reason", and it was approved. While Apple can be arbitrary at times, let's not overstate the risk.
Shaggy Frog
Sorry, I wasn't very clear about this: It should support all orientation variants.
Felixs
A: 

You need to override shouldAutorotateToInterfaceOrientation. A good place to put this is in the app delegate.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && 
        UIInterfaceOrientationIsLandscape(interfaceOrientation))
    {
        return YES;
    }
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && 
        UIInterfaceOrientationIsPortrait(interfaceOrientation)) 
    {
        return YES;
    }   
    return NO;
}

I'm not sure, but this may also support the phone being upside-down, which is a HIG no no. You might want to use interfaceOrientation == UIInterfaceOrientationPortrait instead for the phone.

nevan
N.B. that this code will cause run-time crashes on devices running iOS 3.x.
Shaggy Frog
I'm using something similar to this and it's not crashing on 3.x devices. Is it the `UI_USER_INTERFACE_IDIOM()` that you mean?
nevan
`UIUserInterfaceIdiomPad` is not defined for 3.x devices
Shaggy Frog