Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMediaPickerController orientation on iPad

How can I set correct orientation of MPMediaPickerController ?

I've return YES in shouldAutorotateToInterfaceOrientation, but i have bad frame for Landscape (if show MPMediaPickerController in Portrait first, and conversely).

I've rotating my device chaotically and sometime frame set to correct himself! I've find the method to set frame by rotating - need rotate to 180 degreess. For example, if you have good frame in Portrait, when you rotate to Landscape - you have bad frame (from Portatait), but if you rotate to other landscape (to 180 degreess), then frame set to Landscape... Why ?

How can i set the frame after rotation correct always ?

regards,

like image 697
Sergey Kopanev Avatar asked Sep 10 '10 18:09

Sergey Kopanev


1 Answers

Not sure whether you are interested in the solution or not, since you asked this in 2010. Anyway, after a few searches here is what I found:

  1. MPMediaPickerController DOES NOT SUPPORT LANDSCAPE ORIENTATION.

  2. In order to make the MPMediaPicker appear nicely in landscape orientation, we can make use of PopOverController. Basically, we create a pop over, and insert the picker into it. PopOverController, when displayed properly from the rootViewController, will indeed follow the orientation of the device.

Here is the rough code. It works, but needs some cleaning up. Probably best you check whether the popover is nil or not, otherwise it will just stack up on itself each time the user tap on the button.

- (IBAction)showMediaPicker:(id)sender
{

    MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAny];

    mediaPicker.delegate = self;
    mediaPicker.allowsPickingMultipleItems = YES;
    mediaPicker.prompt = @"Select musics...";


    UIPopoverController *colorPickerPopover = [[[UIPopoverController alloc] 
                                    initWithContentViewController:mediaPicker] retain];               
    [colorPickerPopover presentPopoverFromBarButtonItem:sender 
                                    permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];    

}

A little more note: this IBAction is tied to a Toolbar Bar button.

like image 130
GeneCode Avatar answered Oct 06 '22 18:10

GeneCode