2011-08-24 39 views
9

我的iPhone應用程序有一個有趣的小問題。我有一張桌子和每個單元格的視圖,單擊時,全屏播放視頻,然後當您按下完成時,視頻停止並返回到表格視圖。唯一的問題是,當您在視頻加載的前2到3秒內按下完成時,當視圖返回到表格視圖時,屏幕頂部指示時間和電池電量等的欄不再存在那裏,它只是一個白色的空間。但是如果你在開始的幾秒鐘後按下完成,那麼當你回到桌子視圖時,一切都絕對好!我絕對不知道爲什麼發生這種情況,我在互聯網上發現的唯一的事情是這是一些傢伙幾乎完全一樣的問題,因爲我:關閉MPMoviePlayerController後頂部的消失狀態欄

http://www.iphonedevsdk.com/forum/iphone-sdk-development/53020-disappearing-status-bar.html

這導致我用嘗試:

[UIApplication sharedApplication].statusBarHidden = NO; 

然而這也無處可尋。

當他們點擊一個視頻時執行的代碼:

NSString *path = [[NSBundle mainBundle] pathForResource:currentTitle ofType:@"m4v"]; 
NSURL *url = [NSURL fileURLWithPath:path]; 
movieController = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
[movieController setControlStyle:MPMovieControlStyleFullscreen]; 
[movieController setFullscreen:YES]; 
movieController.view.frame = self.view.bounds; 
[self.view addSubview:movieController.view]; 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; 

和執行的代碼或者當視頻完成時或完成用戶點擊是:

NSLog(@"movieController moviePlayBackDidFinish"); 
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; 

[movieController setFullscreen:NO animated:NO]; 
[movieController.view removeFromSuperview]; 

[movieController release]; 

LiveEventsView *liveEventsView = [[LiveEventsView alloc] initWithNibName:@"LiveEventsView" bundle:nil]; 
UIView *currentView = self.view; 
UIView *theWindow = [currentView superview]; 
UIView *newView = liveEventsView.view; 
newView.frame = CGRectMake(0, 20, 320, 460); 
[currentView removeFromSuperview]; 
[theWindow addSubview:newView]; 
[UIApplication sharedApplication].statusBarHidden = NO; 

如果任何人都可以瞭解這種情況,我會非常感激,因爲這是非常令人沮喪的!

感謝,

馬特

回答

6

也許從當視頻視圖中消失導致了狀態欄動畫的計時問題動畫。

嘗試延遲statusBarHidden = NO調用幾秒鐘。

NSInteger delay = 3; 

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_current_queue(), ^{ 
[UIApplication sharedApplication].statusBarHidden = NO; 
}); 
+0

謝謝,這是行得通的,但它似乎成功延遲的最短時間是1秒,這有點過長。如果它是我可以修復它的唯一方法,那麼它將會執行,但最好在視圖加載後立即顯示,而不是1秒後 –

6

您可以將延遲設置爲浮點數。所以這將是

float delay = 0.1; 

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_current_queue(), ^{ 
     [UIApplication sharedApplication].statusBarHidden = NO; 
     [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque; 
    }); 

我有同樣的問題,並通過修改富格德的代碼解決了它。 0.1秒是可以接受的。我還必須更改狀態欄樣式,因爲它返回了BlackTranslucent條形樣式,原始樣式爲BlackOpaque樣式。但現在工作正常。

3

我發現使用給定的解決方案,內容通常會在狀態欄下消失。這種方法解決了這個問題。對於MPMoviePlayerWillExitFullscreenNotification

註冊

 [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(moviePlayerWillExitFullscreen:) 
               name:MPMoviePlayerWillExitFullscreenNotification 
               object:self.moviePlayer]; 

,然後復位狀態欄上的知名度和刪除,並在主窗口中重新添加RootViewController的,這將確保該視圖的邊界是正確的一次。

- (void)moviePlayerWillExitFullscreen:(NSNotification *)notification { 
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide]; 
    AppDelegate *appDelegate = [UIApplication sharedApplication].delegate; 

    id rootViewController = appDelegate.window.rootViewController; 
    appDelegate.window.rootViewController = nil; 
    appDelegate.window.rootViewController = rootViewController; 
}