Skip to content

Commit

Permalink
Merge pull request #1972 from vishalduggal/timob-8500
Browse files Browse the repository at this point in the history
[TIMOB-8500] iOS: NavBar moves out of place on video player
  • Loading branch information
Stephen Tramer committed Apr 13, 2012
2 parents 65a8697 + 879ce2f commit 863891c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 34 deletions.
3 changes: 0 additions & 3 deletions iphone/Classes/TiMediaVideoPlayerProxy.h
Expand Up @@ -34,9 +34,6 @@
// We need some internal way whether or not to check if it's OK to create a view - this is it.
BOOL reallyAttached;

// On rotate in fullscreen mode on iPad, we need to check if the orientation changed so we can redraw.
BOOL hasRotated;

// Need to preserve status bar frame information when entering/exiting fullscreen to properly re-render
// views when exiting it.
BOOL statusBarWasHidden;
Expand Down
27 changes: 9 additions & 18 deletions iphone/Classes/TiMediaVideoPlayerProxy.m
Expand Up @@ -136,10 +136,6 @@ -(void)configureNotifications
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:movie];

[nc addObserver:self selector:@selector(handleRotationNotification:)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];

//FIXME: add to replace preload for 3.2
//MPMediaPlaybackIsPreparedToPlayDidChangeNotification
}
Expand Down Expand Up @@ -875,14 +871,15 @@ -(void)handleThumbnailImageRequestFinishNotification:(NSNotification*)note
}
}

-(void)handleRotationNotification:(NSNotification*)note
-(void)resizeRootView
{
// Only track if we're fullscreen
if (movie != nil) {
hasRotated = [movie isFullscreen];
}
TiThreadPerformOnMainThread(^{
[[[TiApp app] controller] resizeViewForStatusBarHidden];
[[[TiApp app] controller] repositionSubviews];
}, NO);
}


-(void)handleFullscreenEnterNotification:(NSNotification*)note
{
if ([self _hasListeners:@"fullscreen"])
Expand All @@ -893,7 +890,6 @@ -(void)handleFullscreenEnterNotification:(NSNotification*)note
[event setObject:NUMBOOL(YES) forKey:@"entering"];
[self fireEvent:@"fullscreen" withObject:event];
}
hasRotated = NO;
statusBarWasHidden = [[UIApplication sharedApplication] isStatusBarHidden];
}

Expand All @@ -907,14 +903,9 @@ -(void)handleFullscreenExitNotification:(NSNotification*)note
[event setObject:NUMBOOL(NO) forKey:@"entering"];
[self fireEvent:@"fullscreen" withObject:event];
}
if (hasRotated) {
// Because of the way that status bar visibility could be toggled by going in/out of fullscreen mode in video player,
// (and depends on whether or not DONE is clicked as well) we have to manually calculate and set the root controller's
// frame based on whether or not the status bar was visible when we entered fullscreen mode.
[[[TiApp app] controller] resizeViewForStatusBarHidden:statusBarWasHidden];
[[[TiApp app] controller] repositionSubviews];
}
hasRotated = NO;
[[UIApplication sharedApplication] setStatusBarHidden:statusBarWasHidden];

[self performSelector:@selector(resizeRootView) withObject:nil afterDelay:[[UIApplication sharedApplication] statusBarOrientationAnimationDuration]];
}

-(void)handleSourceTypeNotification:(NSNotification*)note
Expand Down
3 changes: 1 addition & 2 deletions iphone/Classes/TiRootViewController.h
Expand Up @@ -108,10 +108,9 @@

/**
Tells the controller to resize its view to the size of main screen adjusted according to visibility of status bar.
@param statusBarHidden If _YES_, sets view size as if status bar is hidden; otherwise, does not.
@return The bounds of the view after resize.
*/
-(CGRect)resizeViewForStatusBarHidden:(BOOL)statusBarHidden;
-(CGRect)resizeViewForStatusBarHidden;

/**
Tells the controller to reposition all its subviews.
Expand Down
44 changes: 33 additions & 11 deletions iphone/Classes/TiRootViewController.m
Expand Up @@ -630,20 +630,42 @@ -(CGRect)resizeView
// Some controllers (like MPVideoPlayerController) manually hide/show the bar
// based on whether or not they enter a "fullscreen" mode, and upon exiting,
// the root view size needs to be adjusted based on any status bar differences.
-(CGRect)resizeViewForStatusBarHidden:(BOOL)statusBarHidden
-(CGRect)resizeViewForStatusBarHidden
{
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
BOOL currentlyHiding = [[UIApplication sharedApplication] isStatusBarHidden];
if (statusBarHidden != currentlyHiding) {
// Modify the app frame before setting it manually
if (currentlyHiding) { // Bar was previously visible
appFrame.size.width -= TI_STATUSBAR_HEIGHT;
}
else { // Bar was previously invisible
appFrame.size.width += TI_STATUSBAR_HEIGHT;
CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGPoint appCenter = CGPointMake(screenBounds.size.width/2.0f, screenBounds.size.height/2.0f);
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
if (CGRectIsEmpty(statusBarFrame)) {
[[self view] setBounds:screenBounds];
[[self view] setCenter:appCenter];
}
else {
CGRect appBounds = CGRectZero;
switch ([[UIApplication sharedApplication] statusBarOrientation]) {
case UIInterfaceOrientationPortrait:
appCenter.y = appCenter.y + TI_STATUSBAR_HEIGHT/2;
appBounds.size.width = screenBounds.size.width;
appBounds.size.height = screenBounds.size.height - TI_STATUSBAR_HEIGHT;
break;
case UIInterfaceOrientationPortraitUpsideDown:
appCenter.y = appCenter.y - TI_STATUSBAR_HEIGHT/2;
appBounds.size.width = screenBounds.size.width;
appBounds.size.height = screenBounds.size.height - TI_STATUSBAR_HEIGHT;
break;
case UIInterfaceOrientationLandscapeLeft:
appCenter.x = appCenter.x + TI_STATUSBAR_HEIGHT/2;
appBounds.size.height = screenBounds.size.width - TI_STATUSBAR_HEIGHT;
appBounds.size.width = screenBounds.size.height;
break;
case UIInterfaceOrientationLandscapeRight:
appCenter.x = appCenter.x - TI_STATUSBAR_HEIGHT/2;
appBounds.size.height = screenBounds.size.width - TI_STATUSBAR_HEIGHT;
appBounds.size.width = screenBounds.size.height;
break;
}
[[self view] setBounds:appBounds];
[[self view] setCenter:appCenter];
}
[[self view] setFrame:appFrame];
return [[self view] bounds];
}

Expand Down

0 comments on commit 863891c

Please sign in to comment.