- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在寻找有关如何仅允许您的 iOS 应用程序使用某些方向的说明。我知道 UISupportedInterfaceOrientations
和 shouldAutorotateToInterfaceOrientation
但我对它们的用途以及它们如何组合在一起感到有点困惑。
我试图使用 UISupportedInterfaceOrientations
只允许横向方向,这似乎没有影响,直到我研究它并读到它影响初始方向。对此进行测试后,我的应用程序似乎只能在横向模式下打开,但如果屏幕是纵向模式,则会快速旋转。
我知道您可以使用 shouldAutorotateToInterfaceOrientation
来限制允许的方向,例如:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
但是,在网上阅读时,我读到 shouldAutorotateToInterfaceOrientation
从 iOS6 开始被弃用。
基本上我的问题是:
UISupportedInterfaceOrientations
来限制初始定位?编辑:
为了扩展已接受的答案,shouldAutorotate
适用于 iOS6。作为快速修复,如果您已经在 shouldAutorotateToInterfaceOrientation
中实现了您的逻辑和/或您想要支持早期版本的 iOS,您可以执行以下操作:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (BOOL)shouldAutorotate {
return [self shouldAutorotateToInterfaceOrientation:self.interfaceOrientation];
}
最佳答案
您需要用于旋转而不是 shouldAutorotateToInterfaceOrientation
的方法只是 shouldAutorotate
处理旋转,根据 AppleDoc for ViewControllers:
In iOS 6, your app supports the interface orientations defined in your app’s Info.plist file. A view controller can override the supportedInterfaceOrientations method to limit the list of supported orientations. Generally, the system calls this method only on the root view controller of the window or a view controller presented to fill the entire screen; child view controllers use the portion of the window provided for them by their parent view controller and no longer participate in directly in decisions about what rotations are supported. The intersection of the app’s orientation mask and the view controller’s orientation mask is used to determine which orientations a view controller can be rotated into.
You can override the preferredInterfaceOrientationForPresentation for a view controller that is intended to be presented full screen in a specific orientation.
方法 shouldAutorotateToInterfaceOrientation
已弃用,一些处理设备旋转响应的方法也是如此。
对于多版本iOS的支持方法,Apple有另外的说法:
For compatibility, view controllers that still implement the shouldAutorotateToInterfaceOrientation: method do not get the new autorotation behaviors. (In other words, they do not fall back to using the app, app delegate, or Info.plist file to determine the supported orientations.) Instead, the shouldAutorotateToInterfaceOrientation: method is used to synthesize the information that would be returned by the supportedInterfaceOrientations method.
关于iOS - UISupportedInterfaceOrientations 和 shouldAutorotateToInterfaceOrientation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13646134/
我正在寻找有关如何仅允许您的 iOS 应用程序使用某些方向的说明。我知道 UISupportedInterfaceOrientations 和 shouldAutorotateToInterfaceO
我正在为 iOS 应用程序使用 AIR2.6。 在应用程序描述符 XML 文件中,当autoOrients 被声明为 false,然后在 iPad 上只有一个方向可用(landscapeRight,p
Xcode (4) 突出显示了 UISupportedInterfaceOrientations 设置,但无论我如何设置它们,它似乎都不会影响应用程序的基本功能。 Xcode 模板插入注释掉以编程方式
即使在 info.plist 中将 UISupportedInterfaceOrientations 设置为仅纵向,iOS 中是否可以监听方向变化/了解设备当前方向? (我的目标是捕获事件以更改 UI
我是一名优秀的程序员,十分优秀!