0

I'm trying to get one of my xib file to rotate to portrait as if it were the default in the first place.

I have made my app to support only landscape orientations. In the plist I have set "Initial interface orientation to Landscape (right home button)" because of majority of the app runs on landscape mode.

The code I place in my implementation files are :

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations

return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;

}

Now when changing to the view controller that requires the interface to be in portrait mode I have placed this code on the xib file's implementation file to make it go into portrait mode and support portrait mode alone. So that even if the device is lying in landscape mode it would still run the view in portrait mode.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations

return interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortrait;

}

Although this does not seem to work. It just remains in landscape mode and squeezes the image view and other objects I have placed in the xib file. How do I get the xib to rotate to portrait mode? Thanks.

user1677210
  • 169
  • 1
  • 1
  • 13

2 Answers2

0
  change your Xib in Landscape Mode only and then click on your project file then target   then select only Landscape mode or Portrait Mode(left/right or both) 
  then go to this method 
I am using Landscape Mode.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
  // Return YES for supported orientations
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

enter image description here

amit soni
  • 2,183
  • 1
  • 14
  • 17
0

My experience shows that setting UIInterfaceOrientation in the plist file does not have any effect. On the other hand you can force an orientation (for example landscape) at start up time by setting:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
    // your stuff
{

You can use this method also later on to force the logical orientation of the device. Note: this is an "official" method of Apple as of this document

MrTJ
  • 13,064
  • 4
  • 41
  • 63