- Home /
How to Display a UIPopOver on iPad
Using the NativeToolkit to call a view, I anticipated that I would be able to display a view that, when loaded, would immediately display a UIPopOverController.
The view, I imagine, would need to be a transparent view, and the UIPopOver would initialize with a separate view inside it containing the controls I wanted to display. When the player taps outside the PopOver, the PopOver view would be dismissed and the player would return back to Unity.
Is this the right way to do this? I am not having success. I did see another question here that partially addressed using UIPopOver with Unity, so I know it is technically possible. I just need the particulars on how to implement it.
I can display a view just fine. When I try to display my PopOver view, the app appears to be stuck and reports in the iOS SDK console: "PlayerLoop called recursively!". I am trying to be very basic just to get it working. Here is what I have.
In Unity, I have the script that came with NativeToolkit attached to an empty GameObject called GUI. It has, in part:
if( GUI.Button( new Rect( 10, 10, 100, 40 ), "Load PopOver" ) ) // was xPos,yPos,width,height
{
NativeToolkitBinding.activateUIWithController( "PopOver" );
}
In m XCode project, in the NativeTools folder, I have PopOver.h, PopOver.m and PopOver.xib.
PopOver.h:
#import <UIKit/UIKit.h>
@interface PopOver : UIViewController <UIPopoverControllerDelegate, UINavigationControllerDelegate> {
}
@end
PopOver.m:
#import "PopOver.h"
#import "TestViewController.h"
@implementation PopOver
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
}
return self;
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
TestViewController *testViewController = [[TestViewController alloc] init];
UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:testViewController];
[pop setDelegate:self];
[pop presentPopoverFromRect:CGRectMake( 25, 25, 320, 400 )
inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
[pop setPopoverContentSize:CGSizeMake(320, 400)];
[testViewController release];
}
TestViewController.m:
#import "TestViewController.h"
#import "NativeToolkit.h"
#import "PlayerPrefs.h"
@implementation TestViewController
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark NSObject
- (void)dealloc
{
[super dealloc];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.contentSizeForViewInPopover = CGSizeMake(320, 400);
}
- (IBAction)onTouchDone
{
[[NativeToolkit sharedManager] hideViewController:self];
}
I have been successful in having a GUI button in Unity bring up a ViewController that in turn had an iOS UI button toolbar. When the iOS button is pressed, the UIPopOver openes just fine.
What I have not been able to yet accomplish is to open the UIPopover on top of my Unity3d scene without displaying an iOS ViewController window.