Question

I have used following methods for changing the orientation but it doesn't calls. Why it's so?

-(void)viewWillAppear:(BOOL)animated
{
if(self.interfaceOrientation==UIInterfaceOrientationPortrait||self.interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)
        {
            [self potraitFrame];
        }
        else
        {
            [self landScapeFrame];
        }
}

//Auto Rotating Methods

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    BOOL returnval=NO;

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        if(interfaceOrientation==UIInterfaceOrientationPortrait||interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)
        {
            [self potraitFrame];
        }
        else
        {
            [self landScapeFrame];
        }
        returnval = YES;
    }
    return returnval;
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        if(toInterfaceOrientation==UIInterfaceOrientationPortrait||toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)
        {
            [self potraitFrame];
        }
        else
        {
            [self landScapeFrame];
        }
    }
}
-(BOOL)shouldAutorotate
{
    return YES;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    //    UIInterfaceOrientation crntOrntatn = self.interfaceOrientation;
    //    return UIInterfaceOrientationIsLandscape(crntOrntatn) ? crntOrntatn : UIInterfaceOrientationLandscapeLeft;
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        return self.interfaceOrientation;
    }
}

-(NSUInteger)supportedInterfaceOrientations
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        return UIInterfaceOrientationMaskAll;   
    }
}
Était-ce utile?

La solution

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                     duration:(NSTimeInterval)duration
{
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];

if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft
    ||  toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
    Nslog(@"Landscape");
}
else
{

    Nslog(@"Potrait");

}

}

 this code it will be use full for rotation....and u can write in viewwillappear like this


  UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{


    //Do your stuff for landscap

} else if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)

{


}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top