2014-01-06 31 views
1

我正在製作一個包含遊戲中心功能「邀請朋友」的應用程序,因此我根據Game Center編程指南進行製作。iOS:遊戲中心朋友邀請請求查看控制器更改狀態欄顏色當完成

我面臨的主要問題是解僱GKFriendRequestComposeViewController後狀態欄顏色的變化。

在我的應用程序中,我正在使用帶狀態欄燈光風格的黑色界面。當我撥打GKFriendRequestComposeViewController時,狀態欄顏色會更改爲默認值(例如黑色)。 當我通過GKFriendRequestComposeViewController完成我的操作 - 取消或發送邀請時,View Controller將刪除狀態欄顏色,將其變化動畫化爲白色,然後立即變回黑色。

我無法改變這種行爲。這裏是我的代碼:

代碼顯示GKFriendRequestComposeViewController

- (void) inviteFriends 
{ 
    GKFriendRequestComposeViewController *friendRequestViewController = [[GKFriendRequestComposeViewController alloc] init]; 
    friendRequestViewController.composeViewDelegate = self; 
    [friendRequestViewController addRecipientsWithPlayerIDs: nil]; 

    [self presentViewController:friendRequestViewController animated:YES completion:nil]; 
} 

就像在編程指南。

代碼去除GKFriendRequestComposeViewController

- (void)friendRequestComposeViewControllerDidFinish:(GKFriendRequestComposeViewController *)viewController 
{ 
    [self.presentingViewController dismissViewControllerAnimated:YES completion:^{ 
     NSLog(@"this code is never execute"); 
    }]; 

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; 
} 

這裏是我面臨的一些問題。第一:如果我使用的self代替self.presentingViewController我收到此錯誤:

Warning: Attempt to dismiss from view controller <UINavigationController: 0x16d45310> while a presentation or dismiss is in progress! 

所以,我用self.presentedViewController。但是完成塊不會被調用。爲什麼?

我的代碼不會改變這裏的狀態欄的風格,但我在其他應用程序部分採用

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; 

,它工作正常。

順便說一句,myApp-Info.plist包含此設置:

  • 狀態欄最初是隱藏 - NO
  • 狀態欄樣式 - UIStatusBarStyleLightContent
  • 查看基於控制器的狀態欄外觀 - NO

請幫我解決這個問題。謝謝。

+0

對不起,我遇到了同樣的問題,做u如何解決呢 – passol

+0

@passol現在我拋開這個麻煩,後來我決定在每個屏幕上手動控制狀態欄,因爲我的應用程序中有顏色變化。 –

+0

@passol你好,我回到了我的煩惱,如果你解決了它,請寫一個答案。 –

回答

1

試試這個保持的狀態欄。白色iOS7:

- (void)friendRequestComposeViewControllerDidFinish:(GKFriendRequestComposeViewController *)viewController 
{ 
    [self dismissViewControllerAnimated:YES completion:nil]; 
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault; 
} 

確保在您的plist View controller-based status bar appearance設置爲NO。

這 - Warning: Attempt to dismiss from view controller <UINavigationController: 0x14d44a60> while a presentation or dismiss is in progress!意味着你正在呈現一個viewController,而另一個呈現viewController動畫(解僱)。解決這個問題,例如:

這使得一個問題:

[self dismissViewControllerAnimated:YES completion:nil]; 
[self presentViewController:nextViewController animated:YES completion:nil]; 

這就是解決方案:

[self dismissViewControllerAnimated:YES completion:nil]; 
[self performSelector:@selector(delayedPresent:) withObject:nextViewController afterDelay:0.6]; 

- (void)delayedPresent:(UIViewController *)controller 
{ 
    [self presentViewController:controller animated:YES completion:nil]; 
} 
+0

你好,我很抱歉,但我會取消你的答案,並編輯我的問題,因爲我在我的項目中返回到這個問題,不幸的是我不能解決這個答案:( –