为什么 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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这里有一个区别。
info.plist
值指示应用程序支持的方向,而shouldAutorotateToInterfaceOrientation:
指示特定视图可用的方向。如果您查看 < code>这里,明确提到
info.plist
值帮助iOS选择启动的初始方向 应用。I think there is a distinction here. The
info.plist
value indicates the orientations that the app supports whereas theshouldAutorotateToInterfaceOrientation:
indicates the orientations a particular view is available in.If you look
here
, it is clearly mentioned that theinfo.plist
values help iOS choose the initial orientation to launch the application.