Question

My iPhone app supports the upside down interface orientation: When the user turns the phone upside down (so that the home button is on top) the whole user interface is flipped vertically.

However, a problem occurs when trying to present some view controller B from my view controller A (in this example I present the standard mail composer view controller):

- (IBAction)buttonTapped:(id)sender {

    MFMailComposeViewController *mailVC = [MFMailComposeViewController new];
    mailVC.mailComposeDelegate = self;

    [self presentViewController:mailVC animated:YES completion:nil];

}

When this method is triggered the first thing that happens is that (blue) view controller A immediately flips vertically without animation for whatever reason (as seen in the first screenshot) → Why?

Next the presented view controller B moves into the view (as it should) from the bottom.

presenting view controller B

When dismissing view controller B it flips at an instant and the moves out of the view to the top (instead of the direction where it came from, as seen in the second screenshot).

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    [self dismissModalViewControllerAnimated:YES];
}

dismissing view controller B

Is this a bug in iOS or how can I avoid this odd behavior?

(I only want the same standard animation for presenting view controllers as in normal portrait mode - without these flips.)

Was it helpful?

Solution

I guess that MFMailComposeViewController doesn't support upside down interface orientation that's why it could be interpreted as bug. But Apple recommends do not use upside down interface orientation for iPhone apps. The main reason of it could be explained by such example:

  1. User opens application and rotate iPhone to upside down orientation.
  2. At this moment somebody calls him by phone.
  3. User tries to answer the calls and forgets to rotate phone to default portrait orientation.
  4. As result iPhone's microphone is near user's ear and speaker near mouth.

It isn't user-friendly experience.
I would have thought on your site to use upside down orientation or not.

However if using of upside down interface orientation is required condition then you make such trick:
Create category to MFMailComposeViewController and override method supportedInterfaceOrientations to allow support of necessary orientations and import it to class were MFMailComposeViewController is created:

// MFMailComposeViewController+Orientation.h file
#import <MessageUI/MessageUI.h>

@interface MFMailComposeViewController (Orientation)

@end

// MFMailComposeViewController+Orientation.m file
#import "MFMailComposeViewController+Orientation.h"

@implementation MFMailComposeViewController (Orientation)

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}

@end

Notice: I am not sure that this trick would be passed throw Apple application approving center cause of overriding existed methods in category.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top