开发者

MPMoviePlayer leaving a space above NavigationBar

Screenshot found here: http://i.stack.imgur.com/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];

your开发者_StackOverflow中文版MoviePlayer.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];
}
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜