Drew Dutton
Drew Dutton

Reputation: 87

Autorotate Problems

I have:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;

}

in all my view controllers, in the app summary all rotations are selected, in the info.plist all rotations are added to the supported key. I even have:

autoresizesSubviews = YES;

added to all the view controllers just in case since I'm not using nibs.

Now here's where it gets weird. On the iPad, if the device is in landscape before I open the app, then open the app and load a subview it rotates to landscape, until I force close the app and restart it. I've tried deleting the app and rebuilding, I've tried this on several physical devices and still not change. I've even added a NSLog call to the shouldAutoRotate method and it never gets called. I've even tried subclassing UINavigationController with a dummy nag controller and adding the shouldAutoRotate method to the dummy class.

Finally, if I set it to landscape only the status bar will be in the landscape position but the rest of the view will be in standard portrait.

Any ideas on where to start diagnosing this?

Upvotes: 0

Views: 225

Answers (2)

Sergio Prado
Sergio Prado

Reputation: 229

Auto rotation its quite annoying in the new versions of iOS if you wanna do anything a little different from apple's base ViewControllers it will be a pain, so I recommend you to use:

- (void)viewDidAppear:(BOOL)animated {

UIDevice *device = [UIDevice currentDevice];                    //Get the device object
[device beginGeneratingDeviceOrientationNotifications];         //Tell it to start monitoring the accelerometer for orientation
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];    //Get the notification centre for the app
[nc addObserver:self                                            //Add yourself as an observer
       selector:@selector(orientationChanged:)
           name:UIDeviceOrientationDidChangeNotification
         object:device];



}

- (void)viewWillDisappear:(BOOL)animated {

[[NSNotificationCenter defaultCenter] removeObserver:self];

}

and making the animations your self, believe me you will save a lot of hours than trying to set the flags and everything correct with apple defaults methods

- (void)orientationChanged:(UINotifiacion*)notification {

UIDevice *device = (UIDevice *)[notification object];
if (UIInterfaceOrientationIsLandscape([device orientation])) {
  [UIView animateWithDuration:0.4 animations:^{
    self.view.transform = CATransform3DMakeRotation(M_2_PI, 0, 0, 1);
      }];

   }

}

Upvotes: 0

neilvillareal
neilvillareal

Reputation: 3975

Have you set self.window.rootViewController in your AppDelegate's didFinishLaunchingWithOptions? I have noticed that in iOS 5 and below, the app rotates correctly even if you have not set the rootViewController, but you must set it in iOS 6.

It might also be worth noting, that autorotation has changed (slightly?) in iOS 6. Instead of only one method (shouldAutorotateToInterfaceOrientation), there are now two methods (shouldAutorotate and supportedInterfaceOrientations) for autorotation behavior.

Upvotes: 1

Related Questions