问题描述
在我浏览苹果文档时,我看不到打开Game Center的方法,第一个屏幕是用户可以在其中选择排行榜。
As I go through apple documentation, I can't see a way to open Game Center where the first screen is the where the user can choose a leaderboard.
我知道我可以打开一个特定的排行榜屏幕,但我想打开让用户选择一个屏幕。
I know I can open a specific leaderboard screen , but I want to open the screen that let the user choose one. is that possible ?
这是我的代码当前:
GKLeaderboardViewController *viewController = [[GKLeaderboardViewController alloc] init];
viewController.leaderboardDelegate = self;
// Present leaderboard with the user's options saved from prevous launch
viewController.category = self.category;
viewController.timeScope = self.timeScope;
[parent presentModalViewController:viewController animated:YES];
谢谢!!
推荐答案
这是一个没有文档的解决方法,但在我工作的多个游戏已批准:
Here's an undocumented workaround, but which was approved in multiple games I worked on:
GKLeaderboardViewController *viewController = [[GKLeaderboardViewController alloc] init];
viewController.leaderboardDelegate = self;
[viewController popViewControllerAnimated:NO];
[parent presentModalViewController:viewController animated:YES];
[viewController release];
说明:
-
GKLeaderboardViewController
是UINavigationController
- 的子类别控制器自动在排行榜视图控制器的导航堆栈顶部
- 在显示之前,您可以修改导航堆栈
GKLeaderboardViewController
is a subclass ofUINavigationController
- A particular category's view controller is automatically on top of leaderboard view controller's navigation stack
- Before display, you can already modify the navigation stack
- By not animating, popping occurs instantly, and before the view controller is even presented.
您可以跳过设置类别和时间范围,因为您不需要它们您不会显示特定的类别视图控制器)。
You can skip setting the category and time scope since you don't need them (you won't be displaying a particular "category's" view controller). Even if you don't set it, leaderboard view controller will be pushing default view controller on top.
我已经另外发布了 viewController
I have additionally released the viewController
variable (the leaderboard view controller), since parent
view controller will be taking ownership of the object. Not releasing it therefore creates a memory leak and may have other unintended consequences.
iOS 6及更高版本$ c> GKGameCenterViewController 类。弱连接到GameKit,并用 NSClassFromString(@GKGameCenterViewController)!= nil
测试此类的存在。
iOS 6 and later have the GKGameCenterViewController
class. Weak-link to GameKit and test for presence of this class with NSClassFromString(@"GKGameCenterViewController") != nil
. Then, use it as usual.
实例化此类,而不是 GKLeaderboardViewController
,并设置其 viewState
属性设置为 GKGameCenterViewControllerStateLeaderboards
可立即显示排行榜。
Instantiate this class instead of the GKLeaderboardViewController
and set its viewState
property to GKGameCenterViewControllerStateLeaderboards
to have leaderboards show immediately.
这篇关于IPhone - 游戏中心的选择排行榜屏幕 - 怎么显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!