【问题标题】:iOS Error: Supported orientations has no common orientation with the application (iPhone)iOS 错误:支持的方向与应用程序没有共同的方向 (iPhone)
【发布时间】:2015-11-17 02:30:09
【问题描述】:

使用 iOS 8.3

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

我已阅读此official apple answer,它基本上建议您执行以下操作:

在应用委托中:

@implementation AppDelegate

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

在我的控制器中:

-(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

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

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

我之前读到的一些问题:

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'

【问题讨论】:

  • 在 Xcode 中,除了两个横向方向外,还要检查纵向(尽管您评论说 Apple 声称它不应该更改)。
  • @rmaddy,我还有其他具有此配置的应用程序,确实应该将其标记出来,否则应用程序以纵向模式启动(并切片应用程序),所以这是不可能的。

标签: ios objective-c iphone uiimagepickercontroller


【解决方案1】:

概要: application(_:, supportedInterfaceOrientationsForWindow) -> Int 会覆盖 General > Deployment Info。因此,在应用程序委托中提供 supportedInterfaceOrientationsForWindow 后,您可以完全忽略该 .plist。请参阅有关 UIInterfaceOrientationMaskPortrait 的说明。

在 Obj-C 和 Swift 中都尝试过上面的代码,我唯一得到...

'UIApplicationInvalidInterfaceOrientation',原因:'支持的方向与应用程序没有共同的方向,并且[ViewController shouldAutorotate]返回YES'

...是什么时候:

  1. 使用UIInterfaceOrientationPortrait而不是UIInterfaceOrientationMaskPortraitma​​sk是这里的关键字)
  2. supportedInterfaceOrientations返回supportedInterfaceOrientationsForWindow中列出的掩码

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

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

supportedInterfaceOrientations 将覆盖 Deployment Info 并允许在运行时动态区分 iPhone 和 iPad。


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

Obj-C

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

斯威夫特

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

测试 iOS 8.4

【讨论】:

  • 很好解释,问题是我没有将相关的代码块放在 appDelegate.cpp 中并将其放在图像选择器委托中,这就是它不起作用的原因。您想编辑您的答案以便我接受吗? (重点是将代码块放在 c 的 appDelegate 类中)
【解决方案2】:

呃,对我来说,这是我颤动的 main.dart 中的这句话让我大吃一惊:

  await SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft]);

【讨论】:

    猜你喜欢
    • 2012-09-14
    • 1970-01-01
    • 2014-11-19
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    • 1970-01-01
    • 1970-01-01
    • 2013-02-09
    相关资源
    最近更新 更多