2011-08-24 31 views
9

Có một vấn đề nhỏ thú vị với ứng dụng iPhone của tôi. Tôi có chế độ xem với một bảng và mỗi ô, khi được nhấp, phát toàn màn hình video sau đó khi bạn nhấn xong, video dừng lại và quay lại chế độ xem bảng. Vấn đề duy nhất là, khi bạn nhấn hoàn tất trong vòng 2 hoặc 3 giây đầu tiên của quá trình tải video, khi khung nhìn quay trở lại chế độ xem bảng, thanh ở đầu màn hình cho biết thời gian và cường độ pin vv không còn nữa ở đó, nó chỉ là một khoảng trắng. Nhưng nếu bạn nhấn xong sau vài giây đầu tiên, sau đó khi bạn quay lại chế độ xem bảng, mọi thứ đều hoàn toàn ổn! Tôi hoàn toàn không có ý tưởng tại sao điều này đang xảy ra và điều duy nhất tôi tìm thấy trên internet là này đó là một số anh chàng có khá nhiều chính xác cùng một vấn đề như tôi:Thanh trạng thái biến mất ở trên cùng sau khi MPMoviePlayerController bị đóng

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

này dẫn tôi thử sử dụng:

[UIApplication sharedApplication].statusBarHidden = NO; 

Tuy nhiên, điều này cũng không dẫn đến đâu.

Các mã được thực thi khi họ click vào một video:

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]; 

Và mã thực thi hoặc khi video được thực hiện hoặc khi người dùng nhấp thực hiện là:

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; 

Nếu ai cũng có thể làm sáng tỏ tình huống này, tôi sẽ rất biết ơn vì nó cực kỳ bực bội!

Cảm ơn,

Matt

Trả lời

6

Có lẽ hình ảnh động từ khi xem video sẽ biến mất đang gây ra một vấn đề thời gian với các hình ảnh động trên thanh trạng thái.

thử trì hoãn trạng tháiBarHidden = KHÔNG gọi sau một vài giây.

NSInteger delay = 3; 

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

Cảm ơn, điều này có hiệu quả nhưng thời gian ngắn nhất có vẻ như trì hoãn thành công là 1 giây, hơi quá dài. Nếu đó là cách duy nhất tôi có thể sửa nó, thì nó sẽ làm, nhưng tốt hơn là nó sẽ xuất hiện ngay khi khung nhìn tải, thay vì 1 giây sau –

6

Bạn chỉ có thể đặt độ trễ làm phao thay thế. Vì vậy, nó sẽ là

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; 
    }); 

Tôi đã có cùng một vấn đề và giải quyết nó bằng cách sửa đổi mã của người giàu hơn một chút. 0,1 giây là chấp nhận được. Tôi cũng đã phải thay đổi phong cách thanh trạng thái kể từ khi nó trở lại một phong cách thanh BlackTranslucent và bản gốc là phong cách BlackOpaque. Nhưng hoạt động tốt ngay bây giờ.

3

Tôi đã tìm thấy rằng với các giải pháp đã cho, nội dung thường biến mất bên dưới thanh trạng thái. Cách tiếp cận này khắc phục nó.

Đăng ký cho MPMoviePlayerWillExitFullscreenNotification

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

Và sau đó thiết lập lại khả năng hiển thị trên thanh trạng thái và loại bỏ và tái thêm rootViewController từ cửa sổ chính, điều này sẽ đảm bảo rằng các giới hạn của quan điểm là chính xác một lần nữa.

- (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; 
} 
Các vấn đề liên quan