8

如何设置 MPMediaPickerController 的正确方向?

我在 shouldAutorotateToInterfaceOrientation 中返回 YES,但我的 Landscape 框架不好(如果先在 Portrait 中显示 MPMediaPickerController,反之亦然)。

我混乱地旋转我的设备,有时框架设置为纠正自己!我找到了通过旋转设置框架的方法 - 需要旋转到 180 度。例如,如果您在纵向中有良好的框架,当您旋转到横向时 - 您的框架不好(来自 Portatait),但是如果您旋转到其他横向(到 180 度),那么框架设置为横向......为什么?

如何始终正确设置旋转后的框架?

问候,

4

3 回答 3

3

不确定您是否对解决方案感兴趣,因为您在 2010 年问过这个问题。无论如何,经过几次搜索后,我发现:

  1. MPMediaPickerController 不支持横向。

  2. 为了使 MPMediaPicker 在横向上看起来很好,我们可以使用 PopOverController。基本上,我们创建一个弹出窗口,并将选择器插入其中。PopOverController,当从 rootViewController 正确显示时,确实会遵循设备的方向。

这是粗略的代码。它可以工作,但需要一些清理。最好检查一下弹出框是否为 nil,否则每次用户点击按钮时它都会自行叠加。

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

}

多一点注意:这个 IBAction 绑定到一个工具栏按钮。

于 2012-06-28T06:24:19.327 回答
0

I'm simply pushing it onto my navigation controller:

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

mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = NO;
mediaPicker.prompt = @"Select songs...";

[[self navigationController]  pushViewController:mediaPicker animated:YES];

Granted this only works in the context of a navigation controller, but it works and is simple!

于 2012-12-26T01:06:12.350 回答
-1

这是一些示例代码,您可以尝试一下,旋转后您必须在 self.view 的中心设置媒体播放器视图,这里是一些示例代码...您必须首先添加 MediaPlayer 框架...。

NSString* moviePath = [[NSBundle mainBundle] pathForResource:@"PATRON_LOGO_3" ofType:@"mp4"];
NSURL* movieURL = [NSURL fileURLWithPath:moviePath];
 MPMoviePlayerController *playerCtrl =  [[MPMoviePlayerController alloc]initWithContentURL:movieURL];
playerCtrl.scalingMode = MPMovieScalingModeFill;
playerCtrl.controlStyle = MPMovieControlStyleNone;
[playerCtrl.view setCenter:CGPointMake(240, 160)];
[playerCtrl.view setTransform:CGAffineTransformMakeRotation(M_PI/2)];
playerCtrl.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:playerCtrl.view];
[playerCtrl play];

我认为它工作正常,这是用于纵向的横向模式,我们必须根据纵向框架设置框架,例如..

playerCtrl.view.frame = CGRectMake(0, 0, 480, 320);

之后,我们必须设置为视图中心。

于 2012-03-13T13:29:19.777 回答