问题
I need my app to only support portrait orientation. But after upgrading to iOS9, the orientation settings seem to have no effect. I have gone through this answer and here's my apps settings :
but still the app goes into landscape. what am I doing wrong?
回答1:
Please check Info.plist for "Supported interface orientations". It must show Portrait for your requirement. Sometimes it is not updated as project settings in General Tab. If you find landscape orientation over here then remove it.
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
回答2:
There is some sort of bug in iOS9. It completely overlooks the plist file orientation settings. So I had to add this code to each of my UIViewControllers to get portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
return YES;
}
else
{
return NO;
}
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
- (NSUInteger)supportedInterfaceOrientations
#else
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
#endif
{
return UIInterfaceOrientationMaskPortrait;
}
回答3:
Looks like I found the problem. When I viewed the source of my info.plist, this is what I found :
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
No Idea how the UISupportedInterfaceOrientations~ipad
key came into being. It was not initially displayed when viewing as a property list, but started showing in property list after opened as source and saved.
Also there seems to be now way to set this in the general tab. Thanks to SamB and technerd for putting me on the right path.
PS: I am not sure if this is a bug or the intended behavior, so I welcome any insights on this.
来源:https://stackoverflow.com/questions/34566240/cannot-force-app-to-portrait-only-in-ios9