GKLeaderboardViewController *leaderboardController = [[[GKLeaderboardViewController alloc] init] autorelease];
if (leaderboardController != nil) {
// start the leader board view controller
leaderboardController.leaderboardDelegate = self;
leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime;
leaderboardController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
leaderboardController.modalPresentationStyle = UIModalPresentationFullScreen;
leaderboardController.category = #"map1";
RootViewController* rootVC = ((AppDelegate*)[UIApplication sharedApplication].delegate).viewController;
[rootVC presentModalViewController:leaderboardController animated:YES];
}
I have a iPhone app, it works fine with gamecenter.
But when I build a iPad version, the gamecenter leaderboard still display with iPhone Size( 320x480 ).
So I added this:leaderboardController.modalPresentationStyle = UIModalPresentationFullScreen;
but the display is corrupted, the 3 buttons( today, this week, all time ) on tabbar are NOT fullscreen.
and a wood frame too.
you need to use the ModelPresentation Form Sheet which opens not in a full screen:
troller.modalPresentationStyle = UIModalPresentationFormSheet
Related
On iPad UIPopoverPresentationController working fine but on iPhone it is always showing full window modal popup. i am using following code:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
MySecondViewController *contentVC = [storyboard instantiateViewControllerWithIdentifier:#"Pop"];
contentVC.modalPresentationStyle = UINavigationControllerOperationPop; // 13
UIPopoverPresentationController *popPC = contentVC.popoverPresentationController; // 14
contentVC.popoverPresentationController.sourceRect =CGRectMake(100, 130, 280, 230);
self.navigationController.preferredContentSize = CGSizeMake(200, self.parentViewController.childViewControllers.lastObject.preferredContentSize.height-100);
//self.showPop.frame; // 15
contentVC.popoverPresentationController.sourceView =
self.showPop; // 16
popPC.permittedArrowDirections = UIPopoverArrowDirectionAny; // 17
popPC.delegate = self; //18
[self presentViewController:contentVC animated:YES completion:nil];
-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
return UIModalPresentationNone;
}
In ViewController.h Firstly make a property of UIPopoverPresenatationController.
#property(nonatomic,retain)UIPopoverPresentationController *dateTimePopover8;
Then to show PopOverPresentationcontroller
UINavigationController *destNav = [[UINavigationController alloc] initWithRootViewController:dateVC];/*Here dateVC is controller you want to show in popover*/
dateVC.preferredContentSize = CGSizeMake(280,200);
destNav.modalPresentationStyle = UIModalPresentationPopover;
_dateTimePopover8 = destNav.popoverPresentationController;
_dateTimePopover8.delegate = self;
_dateTimePopover8.sourceView = self.view;
_dateTimePopover8.sourceRect = [sender frame];
destNav.modalPresentationStyle = UIModalPresentationPopover;
destNav.navigationBarHidden = YES;
[self presentViewController:destNav animated:YES completion:nil];
You must have noticed that we are presenting View Controller instead of presenting popOver.So we have to hide this in new way also.It hides automatically when we click on screen.
-(void)hideIOS8PopOver
{
[self dismissViewControllerAnimated:YES completion:nil];
}
We have to implement the delegate of UIPopoverPresenatationController in implementation file.Write below delegate method in implementation file.
- (UIModalPresentationStyle) adaptivePresentationStyleForPresentationController: (UIPresentationController * ) controller {
return UIModalPresentationNone;
}
Popover controllers are for use exclusively on iPad devices.
Edit: As stated by Soberman, since iOS 8 it is possible to present popovers on iPhone using public APIs, so this answer is probably not relevant anymore.
As stated in Apple's documentation on UIPopoverController:
Popover controllers are for use exclusively on iPad devices.
So there is no way to use this class in iPhone application unfortunately. But there are a couple of custom third-party implementations of the functionality provided by UIPopoverController which add iPhone support and more. See https://github.com/50pixels/FPPopover for example.
Edit: There also is another highly customizable popover implementation for both iPhone/iPad worth checking out: https://github.com/nicolaschengdev/WYPopoverController.
I have been searching for almost 2 hours on how to implement UIPopoverController in swift language, at the end, i found out that this api are exclusive for iPad devices only.
How will i be able to make a drop down list on iPhone devices?
please someone help me, at lease with the name of the api so that i know what to search for
You can you third party libraries for that:
FPPopover
WEPopover
or if you don't need iOS 7 support you can use iOS 8 new API which answered in this question
UIPopoverPresentationController on iOS 8 iPhone
i depends on your needs. You can show UIPickerView, present an action sheet or segue to another VC and then go back - these are standard ways.
#property(nonatomic,retain) UIPopoverPresentationController *popoverPresentationController;
- (IBAction)showPopover:(id)sender {
UIViewController *popoverViewController = [[UIViewController alloc] initWithNibName:#"NameViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:popoverViewController];
popoverViewController.preferredContentSize = CGSizeMake(280, 200);
navigationController.modalPresentationStyle = UIModalPresentationPopover;
_popoverPresentationController = navigationController.popoverPresentationController;
_popoverPresentationController.delegate = self;
_popoverPresentationController.sourceView = self.view;
_popoverPresentationController.sourceRect = [sender frame];
navigationController.modalPresentationStyle = UIModalPresentationPopover;
navigationController.navigationBarHidden = YES;
[_viewController presentViewController:navigationController animated:YES completion:nil];
}
I have tabbar as Root controller. When i choose camera from view controller then it opens in Portrait mode, and then i change its orientation but it still in portrait mode and when pickerview dismissed and again change main view controller to landscape mpde then all 5 tabbar items are shown on left side. So it looks like all tabbar items icons are get disturbed. Can any one help to change camera orientation when phone orientaiton gets changed?
if (self.pickerView) {
self.pickerView = nil;
}
self.pickerView = [[UIImagePickerController alloc] init];
self.pickerView.delegate = self;
self.pickerView.sourceType = UIImagePickerControllerSourceTypeCamera;
self.pickerView.showsCameraControls = YES;
self.pickerView.wantsFullScreenLayout = YES;
self.pickerView.navigationBarHidden = YES;
self.pickerView.toolbarHidden = FALSE;
self.pickerView.allowsEditing=YES;
[self presentViewController:self.pickerView animated:YES completion:NULL];
I'm using Apple's code to show a GKGameCenterViewController:
GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
if (gameCenterController != nil) {
gameCenterController.gameCenterDelegate = self;
[self presentViewController:gameCenterController animated:YES completion:nil];
}
This is the text describing the code above:
Game Center UI is Displayed by Your View Controller (iOS)
The convention used by Game Kit is for one of your view controllers to present the Game Kit view controller. Your view controller acts as a delegate to the view controller it presents so that it can be informed when the player is finished looking at the presented screen. Listing 2-1 shows most common use of this pattern, which is to show the Game Center user interface. The Game Center view controller displays many different pieces of Game Center content, so most games should offer a button that brings the player to this screen, even if the game also shows Game Center content using a custom user interface.
When I use the recommended code I get to this screen (GameCenter Challenges), which is not what I want:
I have also tried this code:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"gamecenter:"]];
By using that code, I get to the screen I expected to display:
Do I misunderstand something or am I doing something wrong? Shouldn't the first piece of code bring me to the main menu? Why won't it show the leaderboards?
UPDATE
I implemented viewState as suggested by phix23:
GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
if (gameCenterController != nil) {
gameCenterController.gameCenterDelegate = self;
gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
[self presentViewController:gameCenterController animated:YES completion:nil];
}
But, it still displays the same Challenges screen, despite the fact that I want /try to display the Leaderboards screen.
The GKGameCenterViewController which is available since iOS 6 can show the leaderboards, achievements and challenges of your game center enabled application.
You can change the initial view by setting the viewState of the GKGameCenterViewController. If you don't set this property it will show the default view, which is the challenges view in your case. I guess you don't have setup any leaderboards or achievements so there is nothing to be shown.
Try using this code:
-(void)showGameCentersDefaultPage {
GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
if (gameCenterController != nil) {
gameCenterController.gameCenterDelegate = self;
gameCenterController.viewState = GKGameCenterViewControllerStateDefault;
[self presentViewController:gameCenterController animated:YES completion:nil];
}
}
If you want to begin with a specific type of GameCenter Leaderboard you can call the following method with your leaderboardID
- (void)showLeaderboard:(NSString*)leaderboardID {
GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
if (gameCenterController != nil) {
gameCenterController.gameCenterDelegate = self;
//The next three lines are the lines of interest...
gameCenterController.viewState = GKGameCenterViewControllerStateDefault;
gameCenterController.leaderboardTimeScope = GKLeaderboardTimeScopeToday;
gameCenterController.leaderboardCategory = leaderboardID;
[self presentViewController:gameCenterController animated:YES completion:nil];
}
}
For iOS 7.0, I use the following:
Display Leaderboard:
- (void)displayLeaderboard:(UIViewController *)viewController
{
GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
if (gameCenterController != nil) {
gameCenterController.gameCenterDelegate = self;
gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
[viewController presentViewController:gameCenterController animated:YES completion:nil];
}
}
Display Achievements:
- (void)displayAchievements:(UIViewController *)viewController
{
GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
if (gameCenterController != nil) {
gameCenterController.gameCenterDelegate = self;
gameCenterController.viewState = GKGameCenterViewControllerStateAchievements;
[viewController presentViewController:gameCenterController animated:YES completion:nil];
}
}
Note that the view controller trying to use these functions will need to pass itself (i.e. viewController param must be set to some active view controller).
Hope this helps.
Use GKGameCenterViewController and set the view state:
//Create a leaderboard view controller
GKGameCenterViewController *leaderboardViewController = [[GKLeaderboardViewController alloc] init];
leaderboardViewController.viewState = GKGameCenterViewControllerStateLeaderboards;
//Set the time scope (ex. All Time, This Week, Today) and the leaderboard ID
leaderboardViewController.timeScope = GKLeaderboardTimeScopeAllTime;
leaderboardViewController.leaderboardCategory = leaderboardID;
//Set the delegate so we can handle various actions including dismissal
leaderboardViewController.leaderboardDelegate = self;
//Present the view controller
[self presentViewController:leaderboardViewController animated:YES completion:nil];
This code will present a view controller that displays all of your games leaderboards (or the rankings if there is only one). You can also set properties such as which leaderboard to show, the time scope, delegate, etc. Also note that you can do a similar thing with achievements using the GKAchievementViewController.
The code that you provided in your question,
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"gamecenter:"]];
Launches the GameCenter app. This means that iOS will exit your app and switch to GameCenter. This could be confusing to the user. You should also avoid making the user leave your app. Instead, use the GKViewControllers which are presented modally inside of your app.
I am using the following code to dismiss modal view controllers:
- (IBAction)done {
#ifdef __IPHONE_5_0
if ([self respondsToSelector:#selector(presentingViewController)])
[self.presentingViewController dismissModalViewControllerAnimated:YES];
else
#endif
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
If I runt he simulator using iOS 4.3 iPad, it uses self.parentViewController and works fine. However, when I runt he simulator using iOS 6.0 iPad the simulator crashes right after the view is dismissed using self.presentingViewController.
I do not have an actual iPad to test on... any ideas?
EDIT:
below is the code that creates the modal view controller.
NSArray* errors = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Errors" ofType:#"plist"]];
UIViewController* vc;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
DocumentsViewController_iPad* docsVC = [[DocumentsViewController_iPad alloc] initWithNibName:#"DocumentsViewController-iPad" bundle:nil];
docsVC.documents = errors;
docsVC.errors = YES;
docsVC.navTitle = #"Troubleshooting";
vc = docsVC;
} else {
DocumentsViewController* docsVC = [[DocumentsViewController alloc] initWithNibName:nil bundle:nil];
docsVC.documents = errors;
docsVC.errors = YES;
docsVC.navTitle = #"Troubleshooting";
vc = docsVC;
}
vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:vc animated:YES];
[vc release];
A few things:
Yes, you should use dismissViewControllerAnimated:completion: as #rdelmar said
You should call it on presentingViewController, not parent
You can skip going to the presenting controller and dismiss self, it will forward this message to the presenting controller if needed.
dismissModalViewControllerAnimated: is depreciated, use dismissViewControllerAnimated:completion: instead.