MFMailComposeViewController in the landscape

My application is in landscape mod.When I call MFMailComposeViewController through the real view of the model, it comes into landscape mod.I turns the device and MFMailComposeViewController view goes into portrait mode I want to limit this rotation, it should always be only in landscape mode. Is there any way to do this.

+3
source share
4 answers

A subclass of the MFMailComposeViewController class so that you can override it 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 a new class instead 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];
+6
source

, 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 ! .

+2

, :

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

, initWithRootViewController. , MFMailComposeViewController? , , [[MailCompose alloc] init]. MFMailComposeViewController " ", .

. , - .

+1

MFMailComposeViewController. , . this.Now, .

0

Source: https://habr.com/ru/post/1719252/


All Articles