Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by ikeo · Jun 10, 2010 at 06:50 PM · ipadobjective-c

Does anyone have iPad popover examples?

I'm about to start implementing some obj-c UI elements on top of Unity, and was wondering whether anyone had yet created a plugin to show a popover. I've got Unity pro, so I plan to implement this code as a plugin with methods to be called from within scripts in Unity. I'd greatly appreciate any code snippets.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
5

Answer by Tetrad · Jun 10, 2010 at 09:33 PM

Well without going into full detail, UIPopoverView is pretty straight forward.

Here's a simple example.

Header:

@interface MyCustomPicker : NSObject <UIPopoverControllerDelegate, UINavigationControllerDelegate> { UIView* view; // the base view passed in from the custom init function below UIPopoverController* popOver; }

// this is passed in the view created inside AppController.mm,
// I'll leave it as an exercise to the reader as to where to create this class in order to get that variable. - (id)initWithView:(UIView*)appView;

@end

I'm assuming you understand the basics of the language so I won't bore you with the entire implementation:

// this converts a Unity GUI Rect to a CGRect for the purposes of pointing at the button you clicked on assuming iPad resolution - (CGRect)GetMuxedRect:(CGRect)portraitRect { switch( [[UIApplication sharedApplication] statusBarOrientation] ) { case UIInterfaceOrientationPortrait: return portraitRect; case UIInterfaceOrientationPortraitUpsideDown: return CGRectMake( 768 - portraitRect.origin.x - portraitRect.size.width, 1024 - portraitRect.origin.y - portraitRect.size.height, portraitRect.size.width, portraitRect.size.height ); case UIInterfaceOrientationLandscapeLeft: return CGRectMake( portraitRect.origin.y, 1024 - portraitRect.origin.x - portraitRect.size.width, portraitRect.size.height, portraitRect.size.width ); case UIInterfaceOrientationLandscapeRight: return CGRectMake( portraitRect.origin.y - portraitRect.size.height, portraitRect.origin.x, portraitRect.size.height, portraitRect.size.width ); default: return portraitRect; } }

// call this somehow from your C# to Obj-C code bridge. There are several ways to do this - (void)OpenViewInPopover { // You can replace this with something else, like maybe UIImagePickerController MyCustomViewController* vc = [[[MyCustomViewController alloc] initWithNibName:@"MyCustomViewController" bundle:nil] autorelease];
vc.delegate = self; // setup code for your embedded view controller

 self.popOver = [[[UIPopoverController alloc] initWithContentViewController:vc] autorelease];
 popOver.delegate = self;
 [popOver setPopoverContentSize:vc.view.frame.size]; // for your own custom views you'll want this line.


 // in this example, I have a GUI.Button with rect( 5, 384, 100, 40 ) somewhere on screen.  If you have a 3D GUI or something that doesn't use Unity GUI, you'll have to find your own solution for figuring out how to put the arrow pointing the right place.
 [popOver presentPopoverFromRect:[self GetMuxedRect:CGRectMake( 5, 384, 100, 40 )] inView:view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

}

// UIPopOverView delegate methods - (void)popoverControllerDidDismissPopover:(UIPopoverController*)popoverController { // you might want to do something else here, like sending a unity message to change something from what was in the view self.popOver = nil; }

The real work is going to be figuring out how to send information back and forth between your game and the view controller you put in the UIPopOverView. For example, for a simple toggle switch, you'll probably want to call a native code function that sets a bool on your view whenever it changes in game. Likewise, when the bool changes in native code you'll want to send a message back downwards to notify the game.

For sending messages from Unity into the view controller, the pattern I use is to create the MyCustomPicker object on startup, and do a simple singleton style pattern. So outside the @implementation block do something like this:

// static instance that gets set in init MyCustomPicker* selfCustomPicker;

// this is a native function you'd bind to and call from Unity script void OpenCustomPicker() { [selfCustomPicker OpenViewInPopover]; }

Also, if you have a view controller with something like a "done" button (i.e. UIImagePickerController), that done button callback should call the -(void)dismissPopoverAnimated:(BOOL)animated function on your stored UIPopOverView.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image brandonc · Nov 12, 2010 at 01:40 AM 0
Share

Forgive me, I don't really understand how initWithView is called, nor do I understand why it needs to be called since you are presenting the popover at a coordinate. Can you give any further details?

avatar image brandonc · Nov 12, 2010 at 06:08 PM 0
Share

I now understand why you need a view to display the popover, but dont understand how to modify AppController to initialize it.

avatar image ikeo · Aug 18, 2011 at 02:41 AM 0
Share

It's been a long time since I originally posted this question, and now that I've done this a bunch, I should give a tip on what I think the best way to do this is. To avoid mucking around in the AppController create a category on the AppController and put all of your code in there. To get the view controller which you'll put your popover in to you can call [[UIApplication sharedApplication].keyWindow rootViewController]. With older versions of unity, the EAGL view wasn't inside a view controller, so you needed to make a temp view controller to put your popover in. But now they've wrapped up everything inside a view controller, so you can get at it much more easily.

avatar image TedB · Mar 04, 2012 at 06:58 PM 0
Share

This answer is helpful. I would be really grateful if the implementation category class file for the AppController.m could be shared. I understand why making a category is good organization, and I understand that Unity content is now inside a view. I do not understand where to put the reference to [[UIApplication sharedApplication].keyWindow rootViewController]. I like a challenge as much as anyone, but after several days trying to put together the parts from above, I’m really hoping for the details to get a complete example. $$anonymous$$any thanks!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

iPad simulator and Objective-C code 1 Answer

How to view an image selected from photo library's popover in a UIImageView, iPad 0 Answers

How to Display a UIPopOver on iPad 0 Answers

Possible to render a simple colored spot rather than use a PNG? 0 Answers

Multiple Keyboard iOS 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges