centering a uipopover in iPad

pithhelmet picture pithhelmet · Nov 19, 2010 · Viewed 14.8k times · Source

I would like to create a new keyboard for the iPad.

I have designed a view that has the keys and all the underlying work to fill in a textbox as the user presses the keys, and passes the value back to the calling routine when the user presses the return button.

This all works ok.

Now - I want to create this view as a popover.

I have the basic operations complete (pops up and is dismissed)

But now I need some fine tuning help.

Here are my questions...

1) How do I create a popover window centered on the screen without a UIPopoverArrowDirectionAny selection?

2) Ensure the popover window is the size that I created it with in the XIB file (currently, it resizes and removes some of the rightmost size of the window)

Thanks
tony

Answer

George picture George · Feb 22, 2011

To present it with no arrows pass 0 for "permittedArrowDirections":

[popOverController presentPopoverFromRect:rect inView:view permittedArrowDirections:0 animated:YES];

To center it, pass a 1x1 rect located at the center of your view:

CGRect rect = CGRectMake(viewWidth/2, viewHeight/2, 1, 1);
[popOverController presentPopoverFromRect:rect inView:view permittedArrowDirections:0 animated:YES];

Then you have a centered and arrow-free popover.

The bit about removing the arrow could break at any time. They didn't provide a UIPopoverArrowDirectionNone option for a reason, they may choose to throw an exception in the future when 0 is passed, or default to something. Use it at your own risk.