iPad 上的 MPMediaPickerController 方向

发布于 2024-09-18 06:33:32 字数 337 浏览 3 评论 0原文

如何设置 MPMediaPickerController 的正确方向?

我在 shouldAutorotateToInterfaceOrientation 中返回 YES,但我的横向框架很差(如果首先在纵向显示 MPMediaPickerController,反之亦然)。

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

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

问候,

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,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

娇俏 2024-09-25 06:33:32

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

  1. MPMediaPickerController 不支持横向方向。

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

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

- (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 与工具栏按钮相关联。

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.

悲喜皆因你 2024-09-25 06:33:32

我只是将它推到我的导航控制器上:

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

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

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

当然这只能在导航控制器的上下文中工作,但它可以工作并且很简单!

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!

很快妥协 2024-09-25 06:33:32

这是一些示例代码,您可以尝试一下,旋转后,您必须在 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);

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

here is some sample code you can try it one , after rotation you have to set media palyer view in center of self.view, here some sample code... you have to add MediaPlayer Framework at first....

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

i think it works fine , this is for landscape mode for portrait we have to set frame according to portrait frame like..

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

after that we have to set to center of view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文