当以 UIModalPresentationFormSheet 样式模式打开并且用户使视频全屏时,MPMoviePlayerController 控件
Posted
技术标签:
【中文标题】当以 UIModalPresentationFormSheet 样式模式打开并且用户使视频全屏时,MPMoviePlayerController 控件【英文标题】:MPMoviePlayerController controls when opened in a UIModalPresentationFormSheet style modal and the user makes the video fullscreen 【发布时间】:2011-10-12 12:58:24 【问题描述】:在我的 iPad 应用程序中,我有一个 UIButton,它调用 IBAction 来调用视图控制器作为显示视频的模态。我希望模态显示为 720x405,这部分似乎可以正常工作。这是按钮正在执行的 IBAction 代码:
-(IBAction)videoPlayerTest:(id)sender
VideoModalViewController *vc = [[VideoModalViewController alloc] initWithNibName: @"VideoModalViewController" bundle: nil];
vc.fileName = @"testvideo.m4v";
vc.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:vc animated: YES];
vc.view.superview.frame = CGRectMake(0, 0, 720, 405);
vc.view.superview.center = self.view.center;
[vc release];
模态出现在我想要的地方,控件响应 MPMoviePlayerController;慢跑栏,暂停,播放等,但如果用户点击全屏按钮,视频确实可以全屏播放,但之后 MPMoviePlayerController 将不会响应播放器控件上的任何后续点击。如果我删除 modalPresentationStyle 行,它将起作用,但模态出现在全屏视图上,而不是像我想要的 720x405 模态。我添加了观察者来尝试调整框架的大小并在用户使电影控制器全屏并返回窗口时重新调整它,但它似乎根本没有帮助。这是代码。
- (void)willEnterFullscreen:(NSNotification*)notification
NSLog(@"willEnterFullscreen");
[self setModalPresentationStyle:UIModalPresentationFullScreen];
self.view.frame = CGRectMake(0, 0, 1024, 768);
self.view.center = self.view.center;
- (void)willExitFullscreen:(NSNotification*)notification
NSLog(@"willExitFullscreen");
[self setModalPresentationStyle:UIModalPresentationFormSheet];
self.view.frame = CGRectMake(0, 0, 720, 405);
self.view.center = self.view.center;
- (void)playMovie
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullscreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullscreen:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
NSString *videoString = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
NSURL *videoURL = [NSURL fileURLWithPath:videoString];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[self.view addSubview:moviePlayer.view];
moviePlayer.view.frame = CGRectMake(0, 0, 720, 405);
moviePlayer.view.backgroundColor = [UIColor grayColor];
[moviePlayer prepareToPlay];
[moviePlayer play];
这是我的第一篇文章——希望我做得对,并提供了有关我遇到的问题的足够信息。
【问题讨论】:
【参考方案1】:我已经解决了我的问题。我不知道 MPMoviePlayerViewController 并且我创建了它并将其用作我的模态。效果很好。
-(void)playVideo:(NSString *)fileName
NSString *videoString = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
NSURL *videoURL = [NSURL fileURLWithPath:videoString];
mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
[self presentModalViewController:mpViewController animated:NO];
[[mpViewController moviePlayer] play];
-(IBAction)videoPlayerTest:(id)sender
[self playVideo:@"testvideo.m4v"];
我想我会发布我想出的东西,以防万一其他人遇到同样的情况
【讨论】:
以上是关于当以 UIModalPresentationFormSheet 样式模式打开并且用户使视频全屏时,MPMoviePlayerController 控件的主要内容,如果未能解决你的问题,请参考以下文章
当以编程方式将选项卡更改为“更多”中的选项卡时,TabbedPage selectedItem 不会更改