我的应用程序处于横向模式。当我通过当前模型视图调用 MFMailComposeViewController 时,它进入横向模式。我旋转设备并且 MFMailComposeViewController 视图进入纵向模式我想限制这种旋转它应该始终只在横向模式中。有没有办法。。
4 回答
子类化 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];
我发现 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 被解除后也是如此!现在我的应用程序仍然可以自由旋转。
- 亨利
这对我来说非常有用,只是做了一个小改动:
MailCompose *controller = [[MailCompose alloc]
initWithRootViewController:self.navigationController];
...
我确信我必须调用基类initWithRootViewController
方法。否则,MFMailComposeViewController 怎么知道呢?但事实证明,上面的例子仅仅调用[[MailCompose alloc] init]
就足够了。底层的 MFMailComposeViewController“只知道”如何显示自己。
我喜欢这样的惊喜。我发布了这个,以防它对其他人同样具有启发性。
创建一个新控制器并从 MFMailComposeViewController 继承它。在这个控制器中只需编写一个函数 shouldautorotate 事物。创建这个实例。现在它会正常工作。