MFMailComposeViewController 横向

发布于 2024-08-06 10:28:38 字数 149 浏览 9 评论 0原文

我的应用程序处于横向模式。当我通过当前模型视图调用 MFMailComposeViewController 时,它处于横向模式。我旋转设备,MFMailComposeViewController 视图转到纵向模式,我想限制这种旋转,它应该始终仅处于横向模式。有没有方法来做到这一点..

My application is in landscape mod.When i call MFMailComposeViewController through Present model view, it comes in landscape mod.I rotate device and MFMailComposeViewController view goes to portrait mod i want to restrict this rotation it should always be in landscape mod only.Is there any way to do it..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

雪花飘飘的天空 2024-08-13 10:28:38

子类化 MFMailComposeViewController 类,以便您可以重写其 shouldAutorotateToInterfaceOrientation 以按照您喜欢的方式显示它:

@interface MailCompose : MFMailComposeViewController {
}
@end

@implementation MailCompose

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

@end

指定新类代替 MFMailComposeViewController:

MailCompose *controller = [[MailCompose alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"In app email..."];
[controller setMessageBody:@"...email body." isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];

Subclass the MFMailComposeViewController class, so that you can override its shouldAutorotateToInterfaceOrientation to display it however you like:

@interface MailCompose : MFMailComposeViewController {
}
@end

@implementation MailCompose

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

@end

Specify the new class in place of MFMailComposeViewController:

MailCompose *controller = [[MailCompose alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"In app email..."];
[controller setMessageBody:@"...email body." isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];
江湖彼岸 2024-08-13 10:28:38

我发现 MFMailComposeViewController 的一个简单类别也有效。因为我喜欢我的应用程序旋转到任何角度,所以我创建了 &链接在 MFMailComposeViewController+Rotate.h:

#import <Foundation/Foundation.h>
#import <MessageUI/MFMailComposeViewController.h>

@interface MFMailComposeViewController (Rotate)

@end

和 MFMailComposeViewController+Rotate.m

#import "MFMailComposeViewController+Rotate.h"

@implementation MFMailComposeViewController (Rotate)



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    // Return YES for supported orientations
    return YES;
}


- (NSUInteger)supportedInterfaceOrientations {
   // return the desired orientation mask from http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html
   return /*mask*/; 
}

@end

出于我的基线测试目的(iOS 3.1.3),我似乎不需要将其放入根视图控制器中。

值得注意的是,在我这样做之前,在我的应用程序加载 MFMailComposeViewController 之后,即使在 MFMailComposeViewController 被解雇之后,它也会停止旋转到任何其他方向!现在我的应用程序仍然可以自由旋转。

  • 亨利

I found that a simple category for MFMailComposeViewController also worked. Since I like my app to rotate to any angle, I created & linked in MFMailComposeViewController+Rotate.h:

#import <Foundation/Foundation.h>
#import <MessageUI/MFMailComposeViewController.h>

@interface MFMailComposeViewController (Rotate)

@end

and MFMailComposeViewController+Rotate.m

#import "MFMailComposeViewController+Rotate.h"

@implementation MFMailComposeViewController (Rotate)



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    // Return YES for supported orientations
    return YES;
}


- (NSUInteger)supportedInterfaceOrientations {
   // return the desired orientation mask from http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html
   return /*mask*/; 
}

@end

For my base line testing purposes (iOS 3.1.3), I don't seem to need to put it into the root view controller.

It is worth noting that BEFORE I did this, after my app would load MFMailComposeViewController, it would then stop rotating to any other orientation, even after MFMailComposeViewController was dismissed! Now my app remains freely rotatable.

  • Henry
不念旧人 2024-08-13 10:28:38

这对我来说非常有效,只是做了一个小小的改变:

MailCompose *controller = [[MailCompose alloc] 
      initWithRootViewController:self.navigationController];
...

我确信我必须调用基类 initWithRootViewController 方法。否则,MFMailComposeViewController 如何知道它?但事实证明,上面的示例只需调用 [[MailCompose alloc] init] 就足够了。底层 MFMailComposeViewController “只知道”如何显示自身。

我喜欢这样的惊喜。我发布此内容是为了防止它对其他人同样具有启发性。

This worked for me, perfectly, with one minor change:

MailCompose *controller = [[MailCompose alloc] 
      initWithRootViewController:self.navigationController];
...

And I was convinced that I had to call the base-class initWithRootViewController method. Otherwise, how would the MFMailComposeViewController know about it? But it turns out the example above that simply calls [[MailCompose alloc] init] is enough. The underlying MFMailComposeViewController "just knows" how to display itself.

I love happy surprises like this. I posted this in case it is equally illuminating for anyone else.

惟欲睡 2024-08-13 10:28:38

创建一个新控制器并从 MFMailComposeViewController 继承它。在这个控制器中只需编写一个函数 shouldautorotate 即可。创建这个实例。现在它可以正常工作了。

Create a new controller and inherit it from MFMailComposeViewController.In this controller just write one function shouldautorotate thing. Create instance of this.Now it will be working fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文