Search code examples
ipadrotationlandscapeportrait

iPad rotate from portrait to landscape


My view is originally in landscape mode. when a button is taped, a view opens in portrait mode and everything is find upto this point. the problem is when I go back from that view to the root view the view won't rotate correctly. here is the code I use to rotate the view from portrait to landscape,

-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];

//rotate the page to lansscape
CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(-90*0.0174532925);
landscapeTransform = CGAffineTransformTranslate (landscapeTransform, 0.0, 0.0);

[self.navigationController.view setTransform:landscapeTransform];

self.navigationController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight;    
self.navigationController.view.frame  = CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height);
self.navigationController.view.center  = CGPointMake (384.0, 544.0);

[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;
}

here is a screen shot of the root page in landscape mode after returning from the portrait page,

enter image description here

this is how it should look like

enter image description here


Solution

  • -(void)viewWillDisappear:(BOOL)animated
    {
    
    [super viewWillDisappear:animated];
    
    //rotate the page to lansscape
    CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(-90*0.0174532925);
    landscapeTransform = CGAffineTransformTranslate (landscapeTransform, 0.0, 0.0);
    
    [self.navigationController.view setTransform:landscapeTransform];
    
    self.navigationController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight;    
    self.navigationController.view.frame  = CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height+64);
    self.navigationController.view.center  = CGPointMake (384.0, 512.0);
    
    [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;
    
    }
    

    the thing that i had to play around to adjust the landscape view that was appearing after this view that is in portrait mode disappears was this,

    self.navigationController.view.frame  = CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height+64);
    self.navigationController.view.center  = CGPointMake (384.0, 512.0);
    

    I played around with the center point and the frame height to adjust it.