0

My app must NOT auto-rotate at all. But it includes a screen which tells the user to rotate his phone (and not the opposite!). To do that, the ViewController must make an animated rotation (without any rotation event) when the screen is displaying.

So I used

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:animated];
    [super viewWillDisappear:animated];
}

And

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return YES;
}

to make my screen rotate, as every website and documentation recommend.

But only the StatusBar rotates: my NavigationBar remains stuck at the top.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Martin
  • 11,881
  • 6
  • 64
  • 110
  • Seems like possible duplicate of - http://stackoverflow.com/questions/2144520/iphone-allow-landscape-orientation-on-just-one-viewcontroller, http://stackoverflow.com/questions/181780/is-there-a-documented-way-to-set-the-iphone-orientation – rishi Jan 11 '12 at 17:17
  • No, I don't want an auto rotation, I want to set the orientation manualy – Martin Jan 12 '12 at 11:36
  • Just check the first answer of thread- http://stackoverflow.com/questions/2144520/iphone-allow-landscape-orientation-on-just-one-viewcontroller, and you will be able to get your answer. – rishi Jan 12 '12 at 14:40

2 Answers2

0

I would use a CGAffineTransform perhaps on the navigationcontroller view? Simply rotate it using an animation block 90 degrees?

Bob de Graaf
  • 2,630
  • 1
  • 25
  • 43
  • Wow, that's not lovely at all, but it works ! I think it should be a proper way to make it, but at least, this works. – Martin Jan 13 '12 at 17:26
0

this code is helpful for you to resize the navigation bar automatically you can use it in where you create the navigationController & navigation bar

  self.navigationController.navigationBar.autoresizesSubviews = YES;
  self.navigationController.navigationBar.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

above code will work automatically if it is not then you try this will work in all delegates methods of your view controller where you need the change

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:animated];
[self.navigationController shouldAutorotateToInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation];
}

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
   CGRect frame = self.navViewController.navigationBar.frame;
   frame.size = self.view.frame.size;
if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {

    frame.size.height = 44;
} else {
    frame.size.height = 32;
}
self.navViewController.navigationBar.frame = frame;

if navigation controller is rootview controller then check it enables the all orientation supports

   -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
[super shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
[self.navigationController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
        return YES;
    }

you can use this code in viewcontroller delegates listed below according to your requirment

- (void)viewDidAppear:(BOOL)animated
- (void)viewWillAppear:(BOOL)animated
– willRotateToInterfaceOrientation:duration:

– willAnimateRotationToInterfaceOrientation:duration:

– didRotateFromInterfaceOrientation:
Balakrishnan Mca
  • 747
  • 5
  • 11
  • WTF ? That a copy paste of the 3rd answer of http://stackoverflow.com/questions/181780/is-there-a-documented-way-to-set-the-iphone-orientation – Martin Jan 12 '12 at 11:39
  • sorry friend that should happend unfortunately now I edited it. It is the original post i prepared for you. I tested that code http://stackoverflow.com/questions/181780/is-there-a-documented-way-to-set-the-iphone-orientation in my simulator and iPhone its works in simulator and not in iPhone sorry for inconvenience. – Balakrishnan Mca Jan 13 '12 at 09:48
  • Why did you call [self.navigationController shouldAutorotateToInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation]; in your viewDidLoad ? This method should only be overrided, should't it ? – Martin Jan 13 '12 at 17:29