gpt4 book ai didi

iOS 错误 : Supported orientations has no common orientation with the application (iPhone)

转载 作者:可可西里 更新时间:2023-11-01 04:23:16 25 4
gpt4 key购买 nike

使用 iOS 8.3

我有一个横向模式的 View ,我正在尝试打开一个仅纵向 View Controller 。每次我尝试打开它时,应用程序都会崩溃。

我读过这个official apple answer基本上建议执行以下操作:

在应用委托(delegate)中:

@implementation AppDelegate

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
return UIInterfaceOrientationMaskAll;
else /* iphone */
return UIInterfaceOrientationMaskAllButUpsideDown;
}

在我的 Controller 中:

-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}

所以我有,但我仍然收到此崩溃消息:

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [PUUIAlbumListViewController shouldAutorotate] is returning YES

在项目常规设置中我有以下内容(根据苹果的回答不应更改):

settings

我可以看到实际上正在调用这些函数,但没有任何帮助。有什么想法吗?

我之前读到的一些问题:

How to force a UIViewController to Portrait orientation in iOS 6

iOS6: supportedInterfaceOrientations not working (is invoked but the interface still rotates)

Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'

最佳答案

概要: application(_:, supportedInterfaceOrientationsForWindow) -> Int 确实覆盖了 General > Deployment Info。因此,一旦您在应用程序委托(delegate)中提供了 supportedInterfaceOrientationsForWindow,您就可以完全忽略该 .plist。请参阅有关 UIInterfaceOrientationMaskPortrait 的注释。

在 Obj-C 和 Swift 中以各种方式尝试了上面的代码,我唯一一次得到...

'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [ViewController shouldAutorotate] is returning YES'

...是什么时候:

  1. 使用 UIInterfaceOrientationPortrait 代替 UIInterfaceOrientationMaskPortrait(ma​​sk 是这里的关键字)
  2. supportedInterfaceOrientations返回supportedInterfaceOrientationsForWindow
  3. 中列出的掩码

A. 将此 block 放在采用UIApplicationDelegate 协议(protocol)的类中(通常是AppDelegate.mAppDelegate.swift):

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
return UIInterfaceOrientationMaskAll;
else /* iphone */
return UIInterfaceOrientationMaskAllButUpsideDown;
}

supportedInterfaceOrientations 将覆盖部署信息,并允许在运行时动态区分 iPhone 和 iPad。


B. 将此 block 放在您想要特定行为的 UIViewController 子类中(通常是 CustomViewController.mCustomViewController .swift):

Obj-C

-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}

swift

override func supportedInterfaceOrientations() -> Int {
let supported = UIInterfaceOrientationMask.Portrait.rawValue
return Int(supported)
}

已测试 iOS 8.4

关于iOS 错误 : Supported orientations has no common orientation with the application (iPhone),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32169216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com