xcodeipadorientationlandscapeportrait

How to manage portrait and landscape orientation of iPad in Xcode?


I am making iPad Application

and I set the frame of everything in portrait only

but I want the landscape the orientation too

in appTarget I select all the supported interface orientation.

in portrait mode it's working good but when I move it in landscape mode

then my view and my all controls mess out and look very bad

would you please tell me how can I manage all the orientation

and please do tell me in a bit easy detail


Solution

  • try this ..... let say you have a button in bottom corner of your ipad . then how to put this at same location in both landscape and portrait mode ...

    -(NSUInteger)supportedInterfaceOrientations
    {
        if ([[UIApplication sharedApplication] statusBarOrientation]==UIInterfaceOrientationMaskPortrait||[[UIApplication sharedApplication] statusBarOrientation]==UIInterfaceOrientationMaskPortraitUpsideDown) {
            pButton.frame=CGRectMake(self.view.frame.size.width-70, self.view.frame.size.height-70, 70, 70);
        }
        else
        {
           pButton.frame=CGRectMake(self.view.frame.size.width-70, self.view.frame.size.height-70, 70, 70); 
        }
        return (UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight|UIInterfaceOrientationMaskPortraitUpsideDown);
    }
    -(BOOL)shouldAutorotate
    {
        return YES;
    }
    
    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
    
        if ([[UIApplication sharedApplication] statusBarOrientation]==UIInterfaceOrientationMaskPortrait||[[UIApplication sharedApplication] statusBarOrientation]==UIInterfaceOrientationMaskPortraitUpsideDown) {
            pButton.frame=CGRectMake(self.view.frame.size.width-70, self.view.frame.size.height-70, 70, 70);
        }
        else
        {
            pButton.frame=CGRectMake(self.view.frame.size.width-70, self.view.frame.size.height-70, 70, 70);
        }
    
        return YES;
    }
    

    see you have to override these methods to adjust your gui in both modes , and you have to adjust frame of your GUI elements in these methods . . .