13

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

pithhelmet
  • 2,222
  • 6
  • 35
  • 60

3 Answers3

56

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.

George
  • 1,940
  • 18
  • 27
0

I've just been working this one out but wanted to do as much in the storyboard as possible which changes the approach a bit:

1) Select the popover in the storyboard and un-tick Directions Up/Down/Left/Right to get rid of the arrows.

To center it on screen override prepare for segue and do something like this:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    UIStoryboardPopoverSegue* popover = (UIStoryboardPopoverSegue*)segue;
    CGFloat horizontalInset = (self.view.frame.size.width - popover.popoverController.popoverContentSize.width) / (CGFloat)2.0;
    CGFloat verticalInset = (self.view.frame.size.height - popover.popoverController.popoverContentSize.height) / (CGFloat)2.0;
    popover.popoverController.popoverLayoutMargins =
        UIEdgeInsetsMake(
            verticalInset,
          horizontalInset,
            verticalInset,
          horizontalInset);
}

In my case I also found that the popover segue's corner radius didn't match my design so I change the background color to clear to sort that out i.e. add this to the above block:

popover.popoverController.backgroundColor = [UIColor clearColor];

2) In the destination controller for the segue find the attribute 'Popover' and tick 'Use Explicit Size' and put the size of you want it to appear in popover mode.

Oly Dungey
  • 1,603
  • 19
  • 20
0

If you are using a UIPopoverController, it will have an arrow. Here are your choices.

UIPopoverArrowDirectionAny  
UIPopoverArrowDirectionUp
UIPopoverArrowDirectionDown
UIPopoverArrowDirectionLeft
UIPopoverArrowDirectionRight

As you can see there is no UIPopoverArrowDirectionNone

As for the XIB size, in your ViewDidLoad Method of the implementation file, you can set the following.

self.contentSizeForViewInPopover = CGSizeMake(320.0, 360.0);

You can set the size any way you like for the popover.

jabroni
  • 706
  • 1
  • 7
  • 25