【问题标题】:UIPopoverController orientation crash in iOS 6 [duplicate]iOS 6中的UIPopoverController方向崩溃[重复]
【发布时间】:2012-08-09 08:42:01
【问题描述】:

我目前的程序只支持横向。

在 iOS 6 中,它在 UIPopoverController 上崩溃。

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

我启用了 project 的所有方向,它运行良好。但是,我需要对所有视图进行大量更改以仅支持横向。

还有其他简单的方法来修复UIOrientation in UIPopoverController 吗?

【问题讨论】:

  • 嗨@satungod,很遗憾我的回答被版主删除了,因为我已经将它发布在另一个线程上......很公平。请在此处找到此答案:stackoverflow.com/a/12575058/662605 - 我正在添加一个新答案以直接指向另一个答案。

标签: objective-c uipopovercontroller ios6


【解决方案1】:
Use these delegates for orientation,
- (BOOL)shouldAutorotate
{

return YES;
}

-(NSUInteger)supportedInterfaceOrientations

{
return UIInterfaceOrientationMaskLandscape;

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationLandscapeLeft;
}

【讨论】:

    【解决方案2】:

    你这个link。您必须在开始时将您的应用程序设置为支持所有方向。在应用委托中进行更改。

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

    【讨论】:

      【解决方案3】:
      @interface NonRotatingUIImagePickerController : UIImagePickerController
      
      @end
      
      @implementation NonRotatingUIImagePickerController
      
      - (BOOL)shouldAutorotate
      {
          return NO;
      }
      
      @end
      
      UIImagePickerController *picker = [[NonRotatingUIImagePickerController alloc] init];
      

      使用上面的代码,这对我有用。

      【讨论】:

        【解决方案4】:

        新建一个 UIImagePickerController 的子类并添加以下代码:

        @property (nonatomic)NSUInteger supportedInterfaceOrientations;
        
        -(NSUInteger)supportedInterfaceOrientations{
            return _supportedInterfaceOrientations;
        }
        -(BOOL)shouldAutorotate{
            return YES;
        }
        

        像这样使用它:

            if (imagePickerController==nil) {
                imagePickerController = [[WUIImagePickerController alloc]init];//the subclass
                imagePickerController.delegate = self;
                imagePickerController.supportedInterfaceOrientations = UIInterfaceOrientationMaskLandscapeRight;//any orientation you want to set
                if (popoverController==nil) {
                    popoverController = [[UIPopoverController alloc]initWithContentViewController:imagePickerController];
                }
            }
        

        谁知道更好的方法请告诉我。

        【讨论】:

        • 看看丹尼尔的回答。有一个答案链接。
        • 这不是 setter 方法 imagePickerController.supportedInterfaceOrientations = UIInterfaceOrientationMaskLandscapeRight;完全错了……
        【解决方案5】:

        尝试将以下内容添加到您的UIApplicationDelegate

        - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
            return UIInterfaceOrientationMaskAll;
        }
        

        您仍然可以在 Info.plist 文件中设置支持的界面方向,并在每个视图控制器的 supportedInterfaceOrientations: 方法中返回一个掩码。

        【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多