Pergunta

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

Foi útil?

Solução

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 . . .

Outras dicas

Add this to your AppDelegate.m file in order to support both orientations.

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
     return (UIInterfaceOrientationMaskAll);
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top