I have an application that on the iPod Touch/iPhone should not rotate. However, I do have an MFMaiComposeViewController for users to send bug reports. How my app is set up though, nothing can rotate, which is fine, except for this single view. How can I make this rotate to landscape. It is declared in one class like this:
//
// 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
In the .m
- (IBAction)sendEmail:(id)sender {
NSLog(@"ToolsController - Send Email");
NSString *MailTO = @"[email protected]";
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];
}
How can I allow only this view to rotate? Thanks.
Create your own class MyCustomMailComposeViewController
(or whatever) that extends MFMailComposeViewController
. All you need to add to the implementation of this class is:
// For iOS 6.0+
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
// For iOS 4.x and 5.x
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
This code assumes you want just landscape for the mail composer. Simply return YES if you want all orientations.
Then change:
email = [[MFMailComposeViewController alloc] init];
to:
email = [[MyCustomMailComposeViewController alloc] init];