4
votes

I am working on the app which is universal app. Now I want to set the orientation for both means When app launch on iPhone then it open in portrait mode and when the app launch on iPad then it open in landscape mode.

Is it possible ?

4

4 Answers

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

    return NO;
}
2
votes
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  // The device is an iPad running iPhone 3.2 or later.
  // Rotate to landscape
}
else {
  // The device is an iPhone or iPod touch.
  // Rotate to portrait
}

"How does one get UI_USER_INTERFACE_IDOM to work with iOS 3.2?"

0
votes

Also u can use [UIDevice currentDevice].model or [UIDevice currentDevice].systemName to recognise device then in shouldAutoRotate method return interfaceOrientation ==UIInterfaceOrientationLandscapeLeft for ipad and interfaceOrientation ==UIInterfaceOrientationPortrait for iphone based on device type.

0
votes

You can do this by adding some code to your app delegate per my answer here.

Swift code:

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> Int {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return Int(UIInterfaceOrientationMask.Portrait.rawValue)
    } else {
        return Int(UIInterfaceOrientationMask.LandscapeLeft.rawValue | UIInterfaceOrientationMask.LandscapeRight.rawValue)
    }
}