【发布时间】: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) 仍处于横向模式。
你能帮帮我吗!
【问题讨论】:
-
你有没有想过这个问题?
标签: uitableview ios7 mpmovieplayercontroller