How to set desired device orientation for face up / face down orientation
<p>I am developing an app in which I am setting different nibs for portrait and landscape mode. My app rotates for both portrait and both landscape orientations ,but faceup / facedown orientation.</p>

<p>when I put my device in faceup / facedown orientation , it shows none of the nibs. I compromised with logic and set the device orientations programmatically  in <strong>viewWillAppear</strong> like in this way </p>

<pre><code>-(void)viewWillAppear:(BOOL)animated
{

    if ([[UIDevice currentDevice] orientation]==UIDeviceOrientationUnknown || [[UIDevice currentDevice] orientation]==UIDeviceOrientationFaceUp || [[UIDevice currentDevice] orientation]==UIDeviceOrientationFaceDown) 
        [self shouldAutorotateToInterfaceOrientation:UIDeviceOrientationPortrait];      
    else
        [self shouldAutorotateToInterfaceOrientation:[[UIDevice currentDevice]orientation]];           
}
</code></pre>

<p>when this view controller loads  , this logic works perfectly but after navigating from this to another view controller and when I come back to this view controller (by calling  popViewControllerAnimated: method ) , all above statements get executed properly (it executes <strong>IF statement</strong>) and it sets the portrait nib but doesn't rotate the device. It sets Portrait nib in Landscape mode.</p>

<p>My <strong>shouldAutorotateToInterfaceOrientation</strong> method looks like this</p>

<pre><code>-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {


    if ((interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (interfaceOrientation == UIDeviceOrientationLandscapeRight))      
     {
           // code to set landscape nib
           // there is no error in this code and it works properly
     }      
    else if ((interfaceOrientation == UIDeviceOrientationPortrait) || (interfaceOrientation == UIDeviceOrientationPortraitUpsideDown))  
    {
        //code to set portrait nib
  // there is no error in this code and it works properly
    }           
    return YES;
}
</code></pre>

<p>I Searched in a lot of websites and applied all their logics , yet none of them worked. Kindly help me to fix this problem.</p>

<p>Thanks. </p>
