What is the best way of achieving this? I'm using XIBs with universal size classes (same XIB for iphone and ipad) but I want to lock rotation for iphone only.
Asked
Active
Viewed 1,060 times
2 Answers
2
The list of possible orientations should be in the Info.plist file, you can define distinct values for Ipad and Iphone if you want. Take a look on the discussion below:
1
Try this:
For versions less than iOS 6:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
return NO;
}
else
{
return YES;
}
}
For iOS 6+
- (BOOL)shouldAutorotate
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
return NO;
}
else
{
return YES;
}
}

Sujith Thankachan
- 3,508
- 2
- 20
- 25
-
That method is depreciated, unfortunately. – Tom S Nov 04 '14 at 11:52
-
Edited the answer. Use `- (BOOL)shouldAutorotate` – Sujith Thankachan Nov 04 '14 at 11:58
-
I made a category on UINavigationController and it works, thanks :) Small problem though, my alertViews still rotate doh. – Tom S Nov 04 '14 at 13:37
-
The current API for this is `UIDevice.userInterfaceIdiom`. – Kilian Oct 16 '19 at 21:28