首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在相同位置显示UIPopoverController,仅更改箭头偏移量

在相同位置显示UIPopoverController,仅更改箭头偏移量
EN

Stack Overflow用户
提问于 2012-07-05 13:34:50
回答 3查看 9.4K关注 0票数 18

我的目标是通过改变箭头偏移量来保持UIPopoverController的坐标不变。所以基本上我有三个按钮,每个按钮都会显示一个弹出窗口。当显示此弹出窗口时,它会改变屏幕上的位置,但我不希望这样。更清楚地说,请看截图:

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-09-17 15:57:30

对于我的弹出,我希望箭头是左上角,而不是中上角(这是默认的)。

通过设置UIPopoverController的popoverLayoutMargins属性,我成功地获得了下面的结果(屏幕截图)。您可以使用它来减小UIPopoverController内部计算中使用的屏幕区域,以确定在何处显示弹出窗口。

代码:

代码语言:javascript
复制
// Get the location and size of the control (button that says "Drinks")
CGRect rect = control.frame;

// Set the width to 1, this will put the anchorpoint on the left side
// of the control
rect.size.width = 1;

// Reduce the available screen for the popover by creating a left margin
// The popover controller will assume that left side of the screen starts
// at rect.origin.x
popoverC.popoverLayoutMargins = UIEdgeInsetsMake(0, rect.origin.x, 0, 0);

// Simply present the popover (force arrow direction up)
[popoverC presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

我认为你可以通过调整上面的方法来得到想要的结果。

票数 15
EN

Stack Overflow用户

发布于 2012-07-05 13:59:19

你不能用苹果内置的UIPopoverViewController类按原样操作。但是实现你自己的popover视图控制器应该是相当简单和合乎逻辑的(只需要一些非常基本的2D几何图形和一些UIView文档的挖掘)。

票数 1
EN

Stack Overflow用户

发布于 2012-07-05 14:09:24

是的,你可以这样做。您必须使用alpha=0.0f创建aux视图,并使用它来引导箭头。

例如:

代码语言:javascript
复制
auxView = [[UIView alloc] initWithFrame:firstButton.frame];
auxView.alpha = 0.0 ;
auxView.userInteractionEnabled = NO;
[firstButton.superView addSubview:auxView];
[auxView release];

好了,现在你可以使用该视图作为箭头的向导来打开popover。

代码语言:javascript
复制
[thePopoverController presentPopoverFromRect:auxView.bounds inView:auxView
            permitedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];

现在,您只需移动视图:

代码语言:javascript
复制
auxView.frame = secondButton.frame;

如果你愿意的话,可以使用动画来完成这个动作。

还有一件事,对于这种箭头到按钮,我更喜欢箭头接触按钮。您可以使用:

代码语言:javascript
复制
presentPopoverFromRect:CGRectInset(auxView.bounds, 4.0, 4.0)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11338316

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档