我的目标是通过改变箭头偏移量来保持UIPopoverController的坐标不变。所以基本上我有三个按钮,每个按钮都会显示一个弹出窗口。当显示此弹出窗口时,它会改变屏幕上的位置,但我不希望这样。更清楚地说,请看截图:
发布于 2012-09-17 15:57:30
对于我的弹出,我希望箭头是左上角,而不是中上角(这是默认的)。
通过设置UIPopoverController的popoverLayoutMargins
属性,我成功地获得了下面的结果(屏幕截图)。您可以使用它来减小UIPopoverController内部计算中使用的屏幕区域,以确定在何处显示弹出窗口。
代码:
// 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];
我认为你可以通过调整上面的方法来得到想要的结果。
发布于 2012-07-05 13:59:19
你不能用苹果内置的UIPopoverViewController类按原样操作。但是实现你自己的popover视图控制器应该是相当简单和合乎逻辑的(只需要一些非常基本的2D几何图形和一些UIView文档的挖掘)。
发布于 2012-07-05 14:09:24
是的,你可以这样做。您必须使用alpha=0.0f创建aux视图,并使用它来引导箭头。
例如:
auxView = [[UIView alloc] initWithFrame:firstButton.frame];
auxView.alpha = 0.0 ;
auxView.userInteractionEnabled = NO;
[firstButton.superView addSubview:auxView];
[auxView release];
好了,现在你可以使用该视图作为箭头的向导来打开popover。
[thePopoverController presentPopoverFromRect:auxView.bounds inView:auxView
permitedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
现在,您只需移动视图:
auxView.frame = secondButton.frame;
如果你愿意的话,可以使用动画来完成这个动作。
还有一件事,对于这种箭头到按钮,我更喜欢箭头接触按钮。您可以使用:
presentPopoverFromRect:CGRectInset(auxView.bounds, 4.0, 4.0)
https://stackoverflow.com/questions/11338316
复制相似问题