iOS 应用程序不会在 iPhone 上旋转,但会在 iPad 上旋转

标签 ios objective-c xamarin.ios

我制作了我的 gles 应用程序,并在我的 iPad 上对其进行了测试。它应该只在横向模式下工作,所以我有我的 Info.plist像这样

<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>

我只为 iPhone 设置了横向右,因此启动画面正确显示(似乎您无法在 iPhone 上为横向右和横向左设置单独的启动画面)

该应用程序运行良好,但在 friend 的 iPhone 上,该应用程序以纵向模式运行,并且不会旋转到任一横向模式。旋转锁定已关闭。

我没有特别从我的代码中做任何事情来支持旋转,只是设置我的 Info.plist在我的 iPad 上完美运行。

iPhone模拟器自动变成横向,即使我旋转它也保留横向渲染。

这可能是什么原因造成的?我还尝试允许两个景观旋转,但没有骰子。

最佳答案

ios6 引入了处理方向变化的新方法——我猜你 friend 的 iphone 正在运行 ios5。见UIViewController docs看看如何处理这两个版本:

Handling View Rotations

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.

In iOS 5 and earlier, the UIViewController class displays views in portrait mode only. To support additional orientations, you must override the shouldAutorotateToInterfaceOrientation: method and return YES for any orientations your subclass supports. If the autoresizing properties of your views are configured correctly, that may be all you have to do. However, the UIViewController class provides additional hooks for you to implement additional behaviors as needed. Generally, if your view controller is intended to be used as a child view controller, it should support all interface orientations.

When a rotation occurs for a visible view controller, the willRotateToInterfaceOrientation:duration:, willAnimateRotationToInterfaceOrientation:duration:, and didRotateFromInterfaceOrientation: methods are called during the rotation. The viewWillLayoutSubviews method is also called after the view is resized and positioned by its parent. If a view controller is not visible when an orientation change occurs, then the rotation methods are never called. However, the viewWillLayoutSubviews method is called when the view becomes visible. Your implementation of this method can call the statusBarOrientation method to determine the device orientation.

关于iOS 应用程序不会在 iPhone 上旋转,但会在 iPad 上旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14774740/

相关文章:

ios - 当动态链接具有自定义子域时,Firebase 动态链接在 iOS 上不起作用

ios - 从屏幕向上移动时如何在表格 View 中设置滚动偏移量?

ios - 显示带有文本字段输入的警报

ios - Swift 3.0 静态实例,迁移工具的语法变化

iphone - 应用程序中多个 UIWindow 的最佳实践

objective-c - 同步 iOS 和 Mac OS X 数据

iphone - cell.titleLabel的字体设置应该在cellForRowAtIndexPath:方法中的什么位置?

c# - 使用 Newtonsoft Json.Net 反序列化为 IEnumerable 类

xamarin.ios - 在 UIAlertView (iOS, Xamarin) 上添加 UITextView 而不使用任何第三方库

c# - 使用 c#/Xamarin,如何调用类函数?