Xcode (4) highlights the UISupportedInterfaceOrientations settings, but no matter how I set them, it does not appear to affect a basic app's functionality. The Xcode templates insert commented out implementation for programmatically reporting support in:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
In my experience, this code has nothing to do with the app's bundle settings. So, I wrote the following code to automatically report support for orientation based on the app settings.
Why isn't this the default implementation? Did I miss something and this code shouldn't be necessary? (Any improvements anyone can suggest?) I might turn this into a category for UIViewController
/**
* This implementation coordinates the app's orientation support with the app
* bundle settings, simplifying the configuration of the app's support for its
* different orientations.
*/
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
static NSString *_orientationFlagNames[] = {
Nil, // UIDeviceOrientationUnknown
@"UIInterfaceOrientationPortrait", // UIDeviceOrientationPortrait,
@"UIInterfaceOrientationPortraitUpsideDown",// UIDeviceOrientationPortraitUpsideDown,
@"UIInterfaceOrientationLandscapeRight", // UIDeviceOrientationLandscapeLeft [sic]
@"UIInterfaceOrientationLandscapeLeft" // UIDeviceOrientationLandscapeRight [sic]
// UIDeviceOrientationFaceUp
// UIDeviceOrientationFaceDown
};
NSArray *supportedOrientation = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UISupportedInterfaceOrientations"];
BOOL shouldRotate = (interfaceOrientation < sizeof(_orientationFlagNames)/sizeof(NSString*)
&& [supportedOrientation containsObject:_orientationFlagNames[interfaceOrientation]]);
return shouldRotate;
}
I think there is a distinction here. The info.plist
value indicates the orientations that the app supports whereas the shouldAutorotateToInterfaceOrientation:
indicates the orientations a particular view is available in.
If you look here
, it is clearly mentioned that the info.plist
values help iOS choose the initial orientation to launch the application.