UIPopoverController 更改 UIPopoverArrowDirection 的位置

发布于 2024-10-25 18:42:34 字数 328 浏览 8 评论 0原文

我想将 UIPopoverArrowDirection 移至左侧,以便实际箭头不再居中,而是从左侧多出 25%,从右侧多出 75%。

为了帮助理解我的意思,请查看两个屏幕截图,我希望它像第二个一样...

Normal Popover

< img src="https://i.sstatic.net/DqVCu.png" alt="带有我想要的正确放置箭头的 Popover">

问题是没有真正的方法来深入研究 popover 类。 。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沉鱼一梦 2024-11-01 18:42:34

通过指定“presentPopoverFromRect”并使该矩形受到足够的约束,这已经可以通过内置类实现。

example do this

下面是直接从上述代码中取出的代码。额外的绒毛是因为小齿轮位于 UINavigationBar 的 UIToolbar 中。 r 是 UIToolbar 的框架,它正在被调整以击中正确的位置(箭头),否则会稍微偏离中心。 MGSettingsView 是视图控制器(其中包含“启用过渡”、“启用夜间模式”等)。

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];

如果这不是您所要求的,我认为您最好重新表述您的问题。 :)

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

唔猫 2024-11-01 18:42:34

UIPopoverController 类提供了一个简单的从坐标(矩形)显示内容的方法。您可以设置要自动执行的 popoverArrowDirection,仅此而已。根据这些信息,系统将自动显示弹出窗口以适合屏幕并尊重您想要的方向,您不能要求更多。

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.

软甜啾 2024-11-01 18:42:34

检查下面的方法,您可以给出 arrowDirections 方向的矩形。

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文