如何解决为什么UISupportedInterfaceOrientations设置不会影响UIViewController的行为?
| Xcode(4)突出显示了UISupportedInterfaceOrientations设置,但是无论我如何设置,它似乎都不会影响基本应用程序的功能。 Xcode模板插入注释掉的实现,用于以编程方式报告对以下内容的支持:- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
以我的经验,此代码与应用程序的捆绑软件设置无关。因此,我编写了以下代码,以根据应用程序设置自动报告对方向的支持。
为什么这不是默认实现?我错过了什么吗?不需要此代码吗? (有人可以提出任何改进建议吗?)我可能会将其变成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;
}
解决方法
我认为这是有区别的。
info.plist
值指示应用程序支持的方向,而shouldAutorotateToInterfaceOrientation:
值指示特定视图可用的方向。
如果您看到here
,显然会提到mentioned2ѭ值可帮助iOS选择启动应用程序的初始方向。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。