Chandan Shetty SP
Chandan Shetty SP

Reputation: 5117

Ipad device orientation problem

I am presenting MFMailComposeViewController(mailController) using presentModalViewController on my UIViewController, In mailController(subclass of MFMailComposeViewController) class i have overhide shouldAutorotateToInterfaceOrientation as

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

But in my UIViewController class i have overhide shouldAutorotateToInterfaceOrientation as(this is my project need)

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    {
return NO;
    }

After presenting my mailcontroller, if i rotate the device it works perfectly as expected( supporting landscapeleft/right orientation) in iPhone... But the same code is not working in iPad. Am i doing any mistake here? is it is Apple bug?

I am presenting using this api [myViewController presentModalViewController:mailController animated:YES];

and i am getting this warning on both iPhone and iPad The view controller <UINavigationController: 0x7720920> returned NO from -shouldAutorotateToInterfaceOrientation: for all interface orientations. It should support at least one orientation.

Thanks,

Upvotes: 1

Views: 2675

Answers (3)

Underdog
Underdog

Reputation: 805

MFMailComposeViewController *picker=[[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:self.title];
[picker setMessageBody:body isHTML:YES];
[picker shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft];
[picker shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight];
[picker shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait];
[picker shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortraitUpsideDown];
[self  presentModalViewController:picker animated:YES];

This should fix that...

Upvotes: -2

Luke Mcneice
Luke Mcneice

Reputation: 2720

This Method will allow both landscape orientation's:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

Upvotes: 0

Philippe Leybaert
Philippe Leybaert

Reputation: 171734

What you're actually saying is "I don't support ANY orientation", which is of course... not true.

You should return true for at least one orientation. For example:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
   return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

Upvotes: 5

Related Questions