Reputation: 1556
I'm trying to show different orientation depending on device.
On iPhone I want to allow portrait orientation, on iPad I want to allow landscapeleft orientation.
Is that possible?
I tried
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
else {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
}
Upvotes: 0
Views: 467
Reputation: 11257
Add this to your app delegate: (Swift)
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)
}
}
Upvotes: 1
Reputation: 4092
The code you posted does the job. However you need to add Supported Device Orientations to Info.plist. The easiest way to do this is to select appriopriate settings in Project->Target->Summary->Supported Device Orientations
section.
Upvotes: 1