MPMoviePlayer 在导航栏上方留出一个空间

发布于 2024-11-13 04:57:12 字数 4679 浏览 2 评论 0原文

屏幕截图在这里找到: https://i.sstatic.net/fru4x.png

所以我有UITableViewController 推送其中包含 MPMoviePlayer 对象的 UIViewController。我发现,当我将 MPMoviePlayer 作为子视图加载时,它会创建一个状态栏。该状态栏将顶部的导航栏向下推,导致出现空白。我在 stackoverflow 上查看了一堆不同的主题,但似乎没有任何效果:

iPhone:UINavigationController 顶部的奇怪空间

不确定为什么 UIView 被推高了大约 10px< /一>

<一href="https://stackoverflow.com/questions/4671881/empty-white-line-under-uitableview-after-close-mpmoviewplayer-from-fullscreen-m">从全屏关闭 MPMoviewPlayer 后 UITableView 下出现空(白色)行模式

隐藏MPMoviePlayerController 中的 StatusBar

UIViewController 正在使用以下代码 (PresetViewController.m) 进行推送:

-(void)tableView:(UITableView *)tableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger row = [indexPath row];
    //PresetNode *tempNode = [appDelegate.presetData objectAtIndex:row];

   ..... SOME DATA IS LOADED HERE

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
    MoviePlayer *player = [[MoviePlayer alloc] initWithNibName:nil bundle:nil andVideoArray: presetVideoURLs];
    [self.navigationController pushViewController:player animated:NO];
    [player playVideoAtIndex:0];
    [player release];

[tableView deselectRowAtIndexPath:indexPath animated:YES];
}

当视图控制器加载时,由于某种原因,它会加载到其视图顶部的状态栏中,即使我在 MoviePlayer 中使用此代码.m:

- (void)viewDidAppear:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}

我将电影设置为横向模式并播放。然后我检查是否按下了完成按钮。如果按下完成按钮,我会弹出视图。由于某种原因,当视图弹出时,其后面的 uitableviewcontroller 会被下推几个像素。电影播放器​​创建的状态栏将所有内容向下推。这是电影播放器​​代码(MoviePlayer.m):

-(void) playVideoAtIndex: (NSInteger)index{

NSString *rootPath = [[NSBundle mainBundle] resourcePath];
NSString *filePath = [rootPath stringByAppendingPathComponent: [self.movieArray objectAtIndex:index]];
NSURL *fileURL = [NSURL fileURLWithPath:filePath isDirectory:NO];
self.yourMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: fileURL];

[yourMoviePlayer setControlStyle:MPMovieControlStyleFullscreen];



[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
[[UIApplication sharedApplication] setStatusBarHidden:YES];

[[self navigationController] setNavigationBarHidden: YES];

yourMoviePlayer.scalingMode = MPMovieScalingModeFill;
[[yourMoviePlayer view] setTransform:CGAffineTransformMakeRotation(M_PI/2)];
self.yourMoviePlayer.view.frame = self.view.frame;

[yourMoviePlayer setFullscreen:YES animated:NO];

[[NSNotificationCenter defaultCenter] 
 addObserver:self
 selector:@selector(checkForNextMovie:)                                                 
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:yourMoviePlayer];

[[self view]addSubview:yourMoviePlayer.view];
//[[self navigationController] presentMoviePlayerViewControllerAnimated:self];
//---play movie---
[yourMoviePlayer play];    

}

-(void) checkForNextMovie:(NSNotification*) aNotification {
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter] 
 removeObserver:self
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:player];

NSNumber *reason = [[aNotification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];

[yourMoviePlayer release];
if((currentIndex+1) == [self.movieArray count] || [reason intValue] == MPMovieFinishReasonUserExited){
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
    [player.view removeFromSuperview];
    [[self navigationController] setNavigationBarHidden: NO];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    //self.wantsFullScreenLayout = YES;

    [[self navigationController] popViewControllerAnimated:NO];
    if ([UIApplication sharedApplication].statusBarOrientation != self.interfaceOrientation) {
        [[UIApplication sharedApplication] setStatusBarOrientation:self.interfaceOrientation animated:NO];
    }
}
else{
    currentIndex++;
    [self playVideoAtIndex: currentIndex];
}
}

Screenshot found here: https://i.sstatic.net/fru4x.png

So I have a UITableViewController pushing a UIViewController that has a MPMoviePlayer object in it. What i've discovered is that when I load in the MPMoviePlayer as a subview, it creates a statusbar. This statusbar pushes down the navigationbar a the top, causing the white space. I've looked at a bunch of different topics on stackoverflow and nothing seems to work:

iPhone: Weird space at the top of UINavigationController

Not sure why UIView is being nudged up by around 10px

Empty (white) line under UITableView after close MPMoviewPlayer from fullscreen mode

Hide StatusBar from MPMoviePlayerController

The UIViewController is being pushed with the following code (PresetViewController.m):

-(void)tableView:(UITableView *)tableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger row = [indexPath row];
    //PresetNode *tempNode = [appDelegate.presetData objectAtIndex:row];

   ..... SOME DATA IS LOADED HERE

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
    MoviePlayer *player = [[MoviePlayer alloc] initWithNibName:nil bundle:nil andVideoArray: presetVideoURLs];
    [self.navigationController pushViewController:player animated:NO];
    [player playVideoAtIndex:0];
    [player release];

[tableView deselectRowAtIndexPath:indexPath animated:YES];
}

When the view controller loads, for some reason it loads in a statusbar at the top of its view even though I use this code in MoviePlayer.m:

- (void)viewDidAppear:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}

I set the movie to landscape mode and play it. Then I check to see if the done button is pressed. If the done button is pressed, I pop the view. For some reason, when the view gets popped, the uitableviewcontroller behind it gets pushed down by a few pixels. The statusbar the movieplayer created pushes everything down. Here is the movieplayer code (MoviePlayer.m):

-(void) playVideoAtIndex: (NSInteger)index{

NSString *rootPath = [[NSBundle mainBundle] resourcePath];
NSString *filePath = [rootPath stringByAppendingPathComponent: [self.movieArray objectAtIndex:index]];
NSURL *fileURL = [NSURL fileURLWithPath:filePath isDirectory:NO];
self.yourMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: fileURL];

[yourMoviePlayer setControlStyle:MPMovieControlStyleFullscreen];



[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
[[UIApplication sharedApplication] setStatusBarHidden:YES];

[[self navigationController] setNavigationBarHidden: YES];

yourMoviePlayer.scalingMode = MPMovieScalingModeFill;
[[yourMoviePlayer view] setTransform:CGAffineTransformMakeRotation(M_PI/2)];
self.yourMoviePlayer.view.frame = self.view.frame;

[yourMoviePlayer setFullscreen:YES animated:NO];

[[NSNotificationCenter defaultCenter] 
 addObserver:self
 selector:@selector(checkForNextMovie:)                                                 
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:yourMoviePlayer];

[[self view]addSubview:yourMoviePlayer.view];
//[[self navigationController] presentMoviePlayerViewControllerAnimated:self];
//---play movie---
[yourMoviePlayer play];    

}

-(void) checkForNextMovie:(NSNotification*) aNotification {
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter] 
 removeObserver:self
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:player];

NSNumber *reason = [[aNotification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];

[yourMoviePlayer release];
if((currentIndex+1) == [self.movieArray count] || [reason intValue] == MPMovieFinishReasonUserExited){
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
    [player.view removeFromSuperview];
    [[self navigationController] setNavigationBarHidden: NO];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    //self.wantsFullScreenLayout = YES;

    [[self navigationController] popViewControllerAnimated:NO];
    if ([UIApplication sharedApplication].statusBarOrientation != self.interfaceOrientation) {
        [[UIApplication sharedApplication] setStatusBarOrientation:self.interfaceOrientation animated:NO];
    }
}
else{
    currentIndex++;
    [self playVideoAtIndex: currentIndex];
}
}

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

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

发布评论

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

评论(1

一页 2024-11-20 04:57:12

尝试将 viewController.view 的框架 (viewController.view.frame) 设置为占据整个屏幕的 CGRect:

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

手动设置大小应该消除空白。

Try setting the viewController.view's frame (viewController.view.frame) to a CGRect taking up the whole screen:

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

Manually setting the size should get rid of the white space.

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