【问题标题】:Displaying MFMailComposeViewController in landscape横向显示 MFMailComposeViewController
【发布时间】:2009-07-09 02:22:03
【问题描述】:

我的应用是横向的。我想在横向使用 MFMailComposeViewController 但找不到任何关于方向的通知。在横向中,MFMailComposeViewController 仅显示邮件撰写窗口的顶部,在横向时从左侧进入。基本上它覆盖了横向屏幕的一半。有没有办法让邮件撰写窗口以横向而不是纵向显示?

--- 编辑 --- 我想加载邮件撰写的视图是这样派生的:

//from first UIViewController
[self presentModalViewController:secondView animated:YES];

//from secondView (a UIViewController), I load the info view, which is where the mail compose shows
InfoController *infoController = [[InfoController alloc] initWithNibName:@"Info" bundle:[NSBundle mainBundle]];
[self.view addSubview:infoController.view];

从上面看,邮件撰写父视图是第三个加载的。在 info.plist 中,我这样做:

UIInterfaceOrientation = UIInterfaceOrientationLandscapeRight

【问题讨论】:

    标签: cocoa-touch iphone-sdk-3.0 uiviewcontroller


    【解决方案1】:

    我们可以在 Application Delegate 类实现中添加以下代码来覆盖邮件编写器视图控制器的自动旋转。

    @interface MFMailComposeViewController (AutoRotation)
    // to stop auto rotation
    @end
    
    @implementation MFMailComposeViewController (AutoRotation)
    // stop auto rotation
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // should support all interface orientations.
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    @end
    

    【讨论】:

    • 不错!它工作完美(唯一的事情是在 IOS 6 中我使用 -shouldAutorotate 和 -supportedInterfaceOrientations 方法而不是 -shouldAutorotateToInterfaceOrientation :)。谢谢!
    【解决方案2】:

    如果您在嵌套的 UIViewController 上显示 MailViewController,请尝试在主 UIViewController 上显示它。这为我解决了这个问题。我刚刚将主控制器传递给主控制器。

    【讨论】:

    • 为我工作!谢谢!我也找到了原因:在我们的例子中,主视图控制器是一个处理旋转的控制器,而唯一改变它的是 UIInterfaceRotation。邮件编写器根据视图控制器的旋转呈现自己
    • @Dimitris,你能把样品寄给我吗
    • @Ravan 我不知道在哪里可以找到它,我也不认为 5 年前的代码在 iOS 开发中会有用......我相信从那时起事情一定发生了重大变化。
    【解决方案3】:

    我有一个横向应用程序,显示 MFMailComposeViewController 似乎工作正常...

    我的应用有时不得不切换到纵向模式,因为 UIImagePickerController 在横向模式下工作,所以我在视图中使用以下代码重新设置横向模式...

    self.bounds = CGRectMake(0, 0, 480, 320);
    self.center = CGPointMake(160, 240);
    self.transform = CGAffineTransformMakeRotation(M_PI / 2);
    

    MFMailComposeViewController 应该获取这些值并知道如何显示自己。

    【讨论】:

    • 我在 UIViewController 中使用 MFMailComposeViewController 的委托。我必须使用 self.view.bounds 等等。如果我在 UIViewController 的 viewDidLoad 中设置了你的内容,它会加载我不想要的肖像。如果我在显示邮件撰写视图之前立即执行此操作,我会得到与 OP 中相同的结果。
    • 您在邮件撰写视图之前显示了什么样的视图?您是否告诉操作系统您处于横向模式,或者您是在自己画图并让它横着看?
    • 抱歉耽搁了。我已根据您的问题编辑了 OP。请看一看。
    【解决方案4】:

    尝试将“presentModalViewController:”发送到应用程序窗口的 rootViewController(在 AppDelegate 中)。

    我认为这对我有用,因为 MFMailComposeViewController 不能强制 rootViewController 方向,但可以强制由 rootViewController 的 navigationController 推送的 viewController 的方向。

    你需要这样的东西:

        [((AppDelegate *)[UIApplication sharedApplication]).window.rootViewController presentViewController:mailVC animated:YES];
    

    【讨论】:

      【解决方案5】:

      这个对我有用...

      - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
          //    return (YES);
          return (interfaceOrientation==UIInterfaceOrientationLandscapeRight);
      }
      
      - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
      {
          if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
          {
              ......
          }
      }    
      

      【讨论】:

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