UIPopoverController altering location of UIPopoverArrowDirection

天涯浪子 提交于 2020-01-03 15:17:49

问题


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...

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


回答1:


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

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. :)




回答2:


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.




回答3:


Check below method in this you can give the rect for the arrowDirections direction.

- (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated


来源:https://stackoverflow.com/questions/5401747/uipopovercontroller-altering-location-of-uipopoverarrowdirection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!