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 :
- start app and load initial nav controller with view controller that only supports portrait
- push view controller on to stack that supports landscape AND portrait
- rotate view to landscape
- pop view controller
- 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..
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
You can simple use this:--