2

I think the issue here is that I'm trying to call a mediaPicker and that doesn't support other orientations...

Does anyone have a fix for this?

Here is my current code:

- (IBAction)openMediaPicker:(id)sender {
    MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAnyAudio];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = YES; // this is the default
    mediaPicker.modalPresentationStyle = UIModalPresentationPageSheet;
    //mediaPicker.prompt = @"Select items to play";
[self presentModalViewController:mediaPicker animated:YES];
[mediaPicker release];

    // Init a Navigation Controller, using the MediaPicker as its root view controller
    UINavigationController *theNavController = [[UINavigationController alloc] initWithRootViewController:mediaPicker];
    [theNavController setNavigationBarHidden:YES];

    // Init the Popover Controller, using the navigation controller as its root view controller
    popoverController = [[UIPopoverController alloc] initWithContentViewController:theNavController];

    // Make a rect at the size and location of the button I use to invoke the popover
   CGRect popOverRect = chooseMusicButton.frame;

    // Specify the size of the popover
    CGSize MySize = CGSizeMake(520.0, 720.0);

    [popoverController setPopoverContentSize:MySize animated:YES];

    // Display the popover
    [popoverController presentPopoverFromRect:popOverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    popoverController.delegate = self;
}
Alan Taylor
  • 493
  • 4
  • 16

2 Answers2

3

This code is overly complicated. First you present the media picker modally, then you present it as a popover; why? In the popover, you stuff it into a navigation controller before presenting it; why? Presenting a media picker on iPad is much simpler than that:

MPMediaPickerController* picker = 
    [[[MPMediaPickerController alloc] init] autorelease];
picker.delegate = self;
UIPopoverController* pop = 
        [[UIPopoverController alloc] initWithContentViewController:picker];
self.currentPop = pop;
[pop presentPopoverFromRect:[sender bounds] inView:sender
        permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[pop release];

That works in any orientation and even survives rotation while the popover is showing.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I had actually realized the error of my ways, but thanks for making it so clear for anyone else who comes across this Matt! – Alan Taylor Feb 25 '11 at 01:07
0

All pre-defined modal controllers support all orientations but they must be presented from the root view controller for them to behave correctly in orientation and rotation. My guess is that that the "self" in your code is not the root view controller. You may have to re-architect the code a bit to make this happen if possible.

There are other hacks I have seen to make it work without being presented from the root view controller but they all seemed to be asking for trouble such as extending UIViewController with a category to over-ride interfaceOrientation.

If you can present it from the root view controller, it would be the simplest and cleanest but I realize it is not always possible (e.g., it is inside a library you are providing to third party apps to embed).

  • If self is indeed the root view controller, the problem could be the navigation bar getting the mediaPicker (not a root view controller) in its init as its root view controller. Change it to self from mediaPicker. Also make sure you don't confuse between a root view controller (there is only one in an application tied to the app delegate) and any controllers used as a parent of some other controllers in a controller hierarchy. The rotation and orientation logic only works at the topmost level and is not propagated through a controller hierarchy. – Wings of Fancy Jul 23 '10 at 20:32