关闭时横向 MPMoviePlayerViewController 纵向
Posted
技术标签:
【中文标题】关闭时横向 MPMoviePlayerViewController 纵向【英文标题】:MPMoviePlayerViewController in Landscape when dismissed Portrait 【发布时间】:2014-07-16 19:49:08 【问题描述】:我有一个仅用于 PortraitMode 的 TableViewController。现在我想在触摸单元格时播放视频。 在我的 App Delegate 中,我正在使用以下方法:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]])
NSLog(@"ja1");
return UIInterfaceOrientationMaskAllButUpsideDown;
else
if ([[self.window.rootViewController presentedViewController] isKindOfClass:[UINavigationController class]])
NSLog(@"ja2");
// look for it inside UINavigationController
UINavigationController *nc = (UINavigationController *)[self.window.rootViewController presentedViewController];
// is at the top?
if ([nc.topViewController isKindOfClass:[MPMoviePlayerViewController class]])
NSLog(@"ja3");
return UIInterfaceOrientationMaskAllButUpsideDown;
// or it's presented from the top?
else if ([[nc.topViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]])
NSLog(@"ja4");
return UIInterfaceOrientationMaskAllButUpsideDown;
return UIInterfaceOrientationMaskPortrait;
可以在观看视频时转为横向。
我从我的 TableView 中显示 MPMoviePlayerViewController 的一个实例
- (void)playVideo
NSURL *movieURL = [NSURL URLWithString:MYURL];
MPMoviePlayerViewController *c = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
// Remove the movie player view controller from the "playback did finish" notification observers
[[NSNotificationCenter defaultCenter] removeObserver:c
name:MPMoviePlayerPlaybackDidFinishNotification
object:c.moviePlayer];
// Register this class as an observer instead
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:c.moviePlayer];
// Set the modal transition style of your choice
c.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
// Present the movie player view controller
[self presentViewController:c animated:YES completion:^];
// Start playback
[c.moviePlayer prepareToPlay];
[c.moviePlayer play];
现在我遇到了一个问题,当我在横向模式下关闭 MPMoviePlayerViewController 时,我想将它旋转回纵向模式。但我的 MasterViewController (=TableView) 仍处于横向模式。
你能帮帮我吗!
【问题讨论】:
你有没有想过这个问题? 【参考方案1】:在您的 MasterViewController 中实现以下定向方法。这将使您的 MasterViewController 保持纵向。
- (BOOL)shouldAutorotate
return false;
- (NSUInteger)supportedInterfaceOrientations
return UIInterfaceOrientationMaskPortrait;
// Returns interface orientation masks.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
return UIInterfaceOrientationPortrait;
【讨论】:
以上是关于关闭时横向 MPMoviePlayerViewController 纵向的主要内容,如果未能解决你的问题,请参考以下文章
关闭时,横向iPad上带有键盘的模态视图控制器会更改位置[重复]