iphone - UIPopoverController 强制 iPad 进入纵向方向

标签 iphone uipopovercontroller mpmediapickercontroller

我认为这里的问题是我正在尝试调用 mediaPicker 并且它不支持其他方向...

有人能解决这个问题吗?

这是我当前的代码:

- (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;
}

最佳答案

这段代码过于复杂。首先,以模态方式呈现媒体选择器,然后将其呈现为弹出窗口;为什么?在弹出窗口中,您可以在呈现之前将其填充到导航 Controller 中;为什么?在 iPad 上呈现媒体选择器比这简单得多:

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];

它可以在任何方向工作,甚至在弹出窗口显示时可以旋转。

关于iphone - UIPopoverController 强制 iPad 进入纵向方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3257692/

相关文章:

iphone - 设置UITableView contentOffset,然后拖动, View 偏移跳转到新位置

iphone - MonoTouch : UpPopoverController. DidDismiss 未触发

ios - 从弹出框内执行 segue

ios - Arduino 和 iPhone 连接蓝牙 3.0

iphone - 如何打印ASIHTTPRequest的原始数据

ios - Mach-O 链接器错误,将 xcode 升级到 8.0 后未定义的体系结构符号

ios - 在不导出的情况下获取音频文件大小

ipad - 键盘滑回后 UIPopoverController 没有移动到原始位置

ios - 很快,有没有办法让 UIView 类也成为 MPMediaPickerControllerDelegate?

ios - 如何更改 MPMediaPickerController 的语言设置。