Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPopoverController altering location of UIPopoverArrowDirection

I want to move the UIPopoverArrowDirection to the left such that the actual arrow is no longer centered but more 25% from the left and 75% from the right.

To help understand what I mean see the two screen shots I want it to be like the second one...

Normal Popover

The Popover with correctly placed arrow that I want

The problem is that there is no real way to dig down into the popover class...

like image 995
David van Dugteren Avatar asked Mar 23 '11 06:03

David van Dugteren


2 Answers

This is already doable with the builtin class by specifing "presentPopoverFromRect" and making that rect constrained enough.

example doing this

The below is code taken straight out of the code that results in the above. The extra fluff is because the little cogwheel thing is in a UIToolbar in a UINavigationBar. r is the frame of the UIToolbar and it's being tweaked to hit the right spot (for the arrow) or it'd be slightly off-center. MGSettingsView is the view controller (with "Enable transitions", "Enable night mode", etc in it).

UINavigationItem *item = scrollView.navbar.topItem;
UIToolbar *authorTools = (UIToolbar *)[item.rightBarButtonItem customView];
CGRect r = authorTools.frame;
r.size.width = 18;
r.origin.x += 12;

CGSize popoverSize = CGSizeMake(300.f, 500.f);
MGSettingsView *settingsView = [[MGSettingsView alloc] initWithSize:popoverSize];
UIPopoverController *poctl = [[UIPopoverController alloc] initWithContentViewController:settingsView];
settingsView.popover = poctl;
poctl.delegate = self;
poctl.popoverContentSize = popoverSize;
[poctl presentPopoverFromRect:r inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[settingsView release];

If this isn't what you're asking for you'd better rephrase your question I think. :)

like image 183
Kalle Avatar answered Sep 27 '22 18:09

Kalle


The UIPopoverController class provides a simple way to display content from coordinates (Rect). You have the ability to set the popoverArrowDirection you want to autorize, and that's it. From these informations, the system will automatically display the popover to fit in screen and respect the directin you want, you can not ask for more.

like image 43
Ludovic Landry Avatar answered Sep 27 '22 17:09

Ludovic Landry