Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autorotation not working in iOS 7 , works fine in iOS 6

I have an app that supports landscape orientation only on some sections (Photo gallery, video, etc) and all is working fine on iOS 6 with no issues, however, in iOS 7 the app crashes.

So heres my issue :

  1. start app and load initial nav controller with view controller that only supports portrait
  2. push view controller on to stack that supports landscape AND portrait
  3. rotate view to landscape
  4. pop view controller
  5. app crashes
-->
CRASH: **preferredInterfaceOrientationForPresentation must return a supported interface orientation!**
2013-11-06 10:18:06.220 ausopen-iphone-2014[57605:70b] Stack Trace: (
  0   CoreFoundation                      0x03f665e4 __exceptionPreprocess + 180
  1   libobjc.A.dylib                     0x03ce38b6 objc_exception_throw + 44
  2   CoreFoundation                      0x03f663bb +[NSException raise:format:] + 139
  3   UIKit                               0x01366f1c -[UIViewController _preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation:]

+ 580

Other info :

In my info.plist i support portrait and landscape

In my AppDelegate I implement the following method :

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{}

In this method I specify that if the first view (HomeVC) is showing that it should support ALL orientations.

In this method I also specify that if the second view (PhotoVC) is showing that it should also support ALL orientations.

In my first view (HomeVC) i override this method with the following methods so that only portrait mode is supported when the view is showing:

- (BOOL)shouldAutorotate {
    return YES;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
} 

Not sure what has changed in iOS 7 in regards to this because all is working fine in iOS 6. It seems that in iOS 7 the app is not auto rotating back once the landscape view is popped.

Any help would be appreciated..

like image 742
shokaveli Avatar asked Nov 06 '13 16:11

shokaveli


Video Answer


1 Answers

In IOS7.If you use a UINavigationController, the rotate processing way is different!

See UINavigationController, can see it is a subclass of UIViewController, then that is in him there are listed in the above the rotation of the processing method; So wo need to use UINavigationController also do rotate processing,

My way is to add a Category to UINavigationController, do so.

In the Category. M writes

-(BOOL)shouldAutorotate {    
  return [[self.viewControllers lastObject] shouldAutorotate];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {    
  return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; 
}
like image 52
wormlxd Avatar answered Sep 27 '22 17:09

wormlxd