【问题标题】:Ipad device orientation problemIpad设备方向问题
【发布时间】:2010-09-30 05:57:11
【问题描述】:

我在 UIViewController 上使用 presentModalViewController 呈现 MFMailComposeViewController(mailController),在 mailController(MFMailComposeViewController 的子类) 类中,我将 shouldAutorotateToInterfaceOrientation 覆盖为

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

但在我的 UIViewController 类中,我将 shouldAutorotateToInterfaceOrientation 隐藏为(这是我的项目需要)

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    {
return NO;
    }

在展示我的邮件控制器后,如果我旋转设备,它在 iPhone 中可以正常工作(支持横向左/右方向)...但相同的代码在 iPad 中不起作用。我在这里做错了吗?是苹果的bug吗?

我正在使用此 API 进行演示 [myViewController presentModalViewController:mailController animated:YES];

我在 iPhone 和 iPad 上都收到了这个警告视图控制器 <UINavigationController: 0x7720920> returned NO from -shouldAutorotateToInterfaceOrientation: for all interface orientations. It should support at least one orientation.

谢谢,

【问题讨论】:

    标签: iphone cocoa-touch ipad uiviewcontroller


    【解决方案1】:

    你实际上是在说“我不支持任何方向”,这当然......不是真的。

    您应该为至少一个方向返回 true。例如:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    {
       return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    

    【讨论】:

    • 一旦出现邮件控制器并且如果我旋转设备,邮件控制器不会在 iPad 中旋转。但我为 iPhone 使用了相同的代码,它在 iPhone 中正常工作。我认为是苹果虫。
    • 如果是错误,它是在 iPhone 上,而不是在 iPad 上。在任何情况下,此方法都不应该为每个方向返回 FALSE。
    【解决方案2】:

    此方法将允许两个横向:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
    }
    

    【讨论】:

      【解决方案3】:
      MFMailComposeViewController *picker=[[MFMailComposeViewController alloc] init];
      picker.mailComposeDelegate = self;
      [picker setSubject:self.title];
      [picker setMessageBody:body isHTML:YES];
      [picker shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft];
      [picker shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight];
      [picker shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait];
      [picker shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortraitUpsideDown];
      [self  presentModalViewController:picker animated:YES];
      

      这应该可以解决这个问题...

      【讨论】:

      • 它如何以及为什么会起作用?你不是在“设置”一个方向,这只是一遍又一遍地调用“shouldAutorotate”方法,我看不出有什么效果。
      • 抱歉,否决票或标记无法回答问题。我仍然不明白为什么/如何工作。如果我是个白痴并且这确实有效,请告诉我。
      猜你喜欢
      • 1970-01-01
      • 2013-03-14
      • 2011-10-24
      • 1970-01-01
      • 1970-01-01
      • 2011-09-27
      相关资源
      最近更新 更多