如何只旋转MFMailComposeViewController

时间:2013-01-12 17:26:44

标签: objective-c cocoa-touch rotation mfmailcomposeviewcontroller

我的应用程序在iPod Touch / iPhone上不应该旋转。但是,我确实有一个MFMaiComposeViewController供用户发送错误报告。我的应用程序如何设置,没有任何东西可以旋转,这是好的,除了这个单一的视图。如何将其旋转为横向。它在一个类中声明如下:

//
//  LogbookSecondViewController.h
//  Logbook iDM
//
//  Created by Josiah Bruner on 9/20/12.
//  Copyright (c) 2012 Infinite Software Technologies. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>

@interface LogbookSecondViewController : UIViewController  <MFMailComposeViewControllerDelegate>
{
        MFMailComposeViewController *email;
}

@property (nonatomic, retain) MFMailComposeViewController *email;

@end

在.m

- (IBAction)sendEmail:(id)sender {
    NSLog(@"ToolsController - Send Email");
    NSString *MailTO = @"infinite@qualityservice.com";
    email = [[MFMailComposeViewController alloc] init];
    email.mailComposeDelegate = self;
    NSArray *recipitants = [NSArray arrayWithObject:MailTO];
    // Subject
    [email setSubject:@"Bug/Problem/Suggestion, Logbook iDM"];

    [email setToRecipients:recipitants];

    // Present it
    [email setModalPresentationStyle:UIModalPresentationFormSheet];
    [email setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    [self presentViewController:email animated:YES completion:nil];
}


- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    [email dismissViewControllerAnimated:YES completion:nil];

}

如何才允许此视图旋转?感谢。

1 个答案:

答案 0 :(得分:4)

创建自己的MyCustomMailComposeViewController(或其他)扩展MFMailComposeViewController的类。您需要添加到此类的实现中的所有内容是:

// For iOS 6.0+
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

// For iOS 4.x and 5.x
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

此代码假设您只想要邮件编辑器的横向。如果您想要所有方向,只需返回YES。

然后改变:

email = [[MFMailComposeViewController alloc] init];

为:

email = [[MyCustomMailComposeViewController alloc] init];