【问题标题】:'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES' [duplicate]'支持的方向与应用程序没有共同的方向,并且 shouldAutorotate 返回 YES' [重复]
【发布时间】:2013-01-05 14:01:31
【问题描述】:

*我的视图处于景观模式,我正在保存图像,我想要返回该图像,因为我的代码在下面,我收到错误“由于未捕获的异常 'UIApplicationInvalidInterfaceOrientation' 而终止应用程序,原因:'支持的方向与应用程序没有共同的方向,并且 shouldAutorotate 正在返回 YES'" * 我可以为 iphone 做什么?

        `- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

         [self dismissModalViewControllerAnimated:YES];
         [picker release];

              }
             - (void)imagePickerController:(UIImagePickerController *)picker 

                didFinishPickingMediaWithInfo:(NSDictionary *)info {

            [picker dismissModalViewControllerAnimated:NO];

                imageDoodle.image = [info objectForKey:@"UIImagePickerControllerMediaMetadata"];

                 }

               -(IBAction)loadfromalbumclicked:(id)sender

                 {

                UIImagePickerController * picker = [[UIImagePickerController alloc] init];

                picker.delegate = self;

                 picker.allowsEditing=NO;

        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

               // self.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;

              [self presentModalViewController:picker animated:YES];
               }

              -(IBAction)savePrint{
//Save image to iOS Photo Library

                 UIImageWriteToSavedPhotosAlbum(imageDoodle.image, nil, nil, nil);
//Create message to explain image is saved to Photos app library
                 UIAlertView *savedAlert = [[UIAlertView alloc] initWithTitle:@"Saved"  

                message:@"Your picture has been saved to the photo library, view it in the 

               Photos app." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
//Display message alert
             [savedAlert show];
              }`

【问题讨论】:

  • 你解决了吗? @virantporwal
  • 是的,我解决了这个问题
  • 怎么样?请编辑您的问题并解释我有同样的问题....
  • 请问有什么解决办法?

标签: iphone objective-c cocoa-touch ios5 ios6


【解决方案1】:

尝试将 shouldAutoRotate 设置为 NO,看看是否有效。

您可以在 iOS 6.0 或更高版本中使用 shouldAutoRotate 和 supportedInterfaceOrientations 方法,而不是(不推荐使用的) shouldAutoRotateToInterfaceOrientation 方法。

类似的东西-

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}


- (BOOL) shouldAutorotate {
    return YES;
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

【讨论】:

  • 你能告诉我是什么问题吗?
  • 我也一样,但我得到同样的错误......
  • 谢谢我试过这个解决方案,它有效。
  • 这里为我做的技巧是preferredInterfaceOrientationForPresentation
  • 在设备方向中取消选中倒置后修复。在 Objective-C 中永远不必担心这一点。
【解决方案2】:

您仅支持有限的方向,横向或纵向。但是您在视图控制器中调用了不同的方向。

您可以看到以下带有支持的方向的图像。它只支持横向和横向。所以如果我调用纵向它会像你一样显示错误。因此,如果您想同时支持这两种方向,请在摘要中进行更改。

See this answer for more detail. 希望对您有所帮助。

编辑

所以你必须把这段代码放在你的视图控制器中

  - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
  return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |   UIInterfaceOrientationMaskLandscapeRight;
 }

【讨论】:

  • 我只选择了风景
【解决方案3】:

如果 plist 中支持的界面方向与 -(NSUInteger)supportedInterfaceOrientations 返回的界面方向不匹配,则会引发此错误

请记住,supportedInterfaceOrientations 返回的 NSUInteger 必须是 UIInterfaceOrientationMask,注意 -MASK-,我曾经犯过简单地返回 UIInterfaceOrientation i.s.o 的错误。 ...掩码值(对您来说是自动完成的)

例如

- (NSUInteger) supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
    // and NOT UIInterfaceOrientationPortrait;
}

【讨论】:

  • 我也不好意思说我也是这么做的。我什至知道我需要 MASK 常量,但不知何故,我只是没有看到自动完成功能给了我其他东西。
【解决方案4】:

注意:如果您使用UIImagePickerControllerUIPopoverController 并且这些error 出现,那么以下这些解决方案非常好。

这些错误也只出现在iOS 6.0

新建一个UIImagePickerController'scategoryadd

@implementation UIImagePickerController(custom)

  -(BOOL)shouldAutorotate
  {
    return NO;
  }
@end

这对我有用。

【讨论】:

  • hi price 它在 ios7 中不起作用,并返回纯白色选择器视图,没有任何取消或完成按钮。你有什么想法来解决这个问题。谢谢
【解决方案5】:

如果你使用的是 cocos2d v2.1,你可以试试这个 for Portrait。

    -(NSUInteger)supportedInterfaceOrientations {

    // iPhone only
    if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
        return UIInterfaceOrientationMaskPortrait;

    // iPad only
    return UIInterfaceOrientationMaskPortrait;
}

// Supported orientations. Customize it for your own needs
// Only valid on iOS 4 / 5. NOT VALID for iOS 6.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // iPhone only
    if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
        return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    // iPad only
    // iPhone only
    return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

支持的方向自动旋转方向应该相同

【讨论】:

    【解决方案6】:

    对于iOS 6.0,如果你的应用只支持横向模式,当你弹出UIImagePickerController时,它会崩溃。

    我的解决方案是将以下类别添加到 UIImagePickerController:

    @interface UIImagePickerController (oritation)
    
    @end
    
    @implementation UIImagePickerController (oritation)
    
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskLandscape;
    }
    
    @end
    

    【讨论】:

    • 谢谢,我会记住这一点.....:)
    • 但是如何调用这个方法呢? ` [选择器支持的接口方向];'像这样?
    【解决方案7】:

    我遇到了同样的错误,可能是以下一种或多种返回冲突的方向:

    • 检查您的 -Info.plist,获取关键的“支持的界面方向”
    • 通过在项目导航器中单击您的应用程序来检查您的摘要窗格。
    • 正如其他人所提到的,检查supportedInterfaceOrientations 方法返回的内容。

    我通过在 -Info.plist 中明确定义单独的“支持的界面方向 (iPad)”和“支持的界面方向 (iPhone)”键来解决我的问题,因为我希望不同设备有不同的方向。

    祝你好运!

    【讨论】:

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