4

I have 5 view in storyboard. I want each view orientation will be different for example one view will be UIInterfaceOrientationLandscapeRight another view will be UIInterfaceOrientationLandscapeLeft or UIInterfaceOrientationPortrait or UIInterfaceOrientationPortraitUpsideDown. So how do set this orientation of view different.

I have used [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight]; but it show warning 'UIDevice may not responds to setOrientation'. According to many of the stackoverflow writers I am using

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 
    //return UIInterfaceOrientationLandscapeLeft;
    return (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); 
}

this above code but it is not working in my project. So what is the proper procedure for the orientation of the screen. Thanks in advance.

David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205
Banshidhari
  • 478
  • 2
  • 12

3 Answers3

2

Try this

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];

You cann't set UIDeviceOrientation because it's physical parameter. If you keep device in your hand in portrait - how you programmatically set it to landscape?). UIDeviceOrientation does mean - Device Orientation, not Interface. This answer describe differences between orientations: https://stackoverflow.com/a/3897243/194544

Community
  • 1
  • 1
beryllium
  • 29,669
  • 15
  • 106
  • 125
0

You have to put -(BOOL)shouldAutorotateToInterfaceOrientation: into each viewController and check for the correct orientation. If you push a viewController that only supports eg. upsideDown, it will be presented upside down.

Note:

  • If you are in a tabbar environment, the behaviour is different. Please ask, if that is the case.
  • If you are talking about the rootViewController your app should be setup corresponding to the first viewController (Info.plist)
calimarkus
  • 9,955
  • 2
  • 28
  • 48
0

The orientation property on UIDevice is read-only.

You can use [UIViewController attemptRotationToDeviceOrientation]; to attempt to rotate all view controllers to the devices current orientation. You can't force set the rotation.

David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205