- 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/
我编写了一个通用应用程序,并且在“shouldAutorotateToInterfaceOrientation”方法中返回了 YES。该方法被调用,但每当我更改 Iphone 或 Ipad 的方向时,
我一直在以纵向模式编写我的通用应用程序,现在大约 15 个 nib 文件,很多很多 viewCotnrollers,我想实现 shouldAutorotateToInterfaceOrientatio
我们的应用被拒绝了,因为该应用没有以倒置的方向旋转。 所以我们有一个标签栏应用程序,将此代码添加到所有标签... shouldAutorotateToInterfaceOrientation 没有意义
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
我的 UIViewController 中有以下代码,我正在设备和模拟器中测试 iOS 5。 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInt
在我的项目设置中,我将支持的界面方向设为横向。 我是否仍应在每个 View Controller 中实现以下内容? - (BOOL)shouldAutorotateToInterfaceOrienta
我通过在 Controller 的 .h 文件中声明它使其可访问, 但我不喜欢仅出于测试目的而更改方法的可见性。 有没有其他方法可以使用 Objective-C 调用此方法, 前任。通过临时从测试类更
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if (in
我有一个横向应用程序,如果设备翻转,我想旋转 180 度。然而,在我的主视图 Controller 中,shouldAutorotateToInterfaceOrientation 根本没有被调用。为
我正在使用 UISplitViewController,当我启动模拟器时,出现以下错误: “对于所有界面方向, View Controller 从 -shouldAutorotateToInterfa
我正在尝试在我的应用程序中实现自动旋转,该应用程序基本上是 UINavigationController,其中有很多 UIViewControllers 被推送到它上面。 我已经将它复制粘贴到我的第一
我想允许方向根据对 View Controller 的 shouldAutorotateToInterfaceOrientation 调用进行旋转。但是,我希望它立即执行此操作并跳过旋转动画(导致整个
我有一个关于 shouldAutorotateToInterfaceOrientation 的问题: 我有一个 GridView Controller ,我在自动旋转方法中放置了一个断点,它会查看该方
我从 lldb 收到以下警告: The view controller returned NO from -shouldAutorotateToInterfaceOrientation: for al
我经常看到这样的代码: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrient
好吧,我不完全确定我是否会充分解释这一点,但就这样吧。 在我的应用程序中,我有多个 viewController,它们被添加和删除以显示不同的 View ,等等。其中一些 Controller ,我想
我正在寻找有关如何仅允许您的 iOS 应用程序使用某些方向的说明。我知道 UISupportedInterfaceOrientations 和 shouldAutorotateToInterfaceO
我在 Deployment Info 下将支持的界面方向设置为除纵向倒置外的所有界面方向。 我想覆盖 shouldAutorotateToInterfaceOrientation: 自定义行为。 (即
我正在从事 iOS 5 目标项目。我的定位方法如下。 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)in
我是 Swift 的新手。我想检测设备是否正在旋转(纵向或横向)。当然,我在 Swift 中需要它。 objective-c 代码: [[UIDevice currentDevice] beginGe
我是一名优秀的程序员,十分优秀!