2

我有一个在 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

在他们中

- (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];

}

我怎样才能只允许这个视图旋转?谢谢。

4

1 回答 1

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];
于 2013-01-12T20:30:52.687 回答