将UIPopoverController置于相同位置,仅更改箭头偏移量

got*_*878 18 objective-c uipopovercontroller ios ios5

我的目标是为UIPopoverController保持相同的坐标,只需改变箭头偏移量.所以基本上我有三个按钮触摸每个按钮显示一个弹出窗口.当呈现此弹出窗口时,它会更改屏幕上的位置,但我不希望这样.要更清楚地看一下screenoshots:

在此输入图像描述

在此输入图像描述

在此输入图像描述

Zyp*_*rax 15

对于我的popover,我希望箭头是左上角而不是顶部中心(这是默认值).

我通过设置popoverLayoutMarginsUIPopoverController 的属性设法得到下面的结果(截图).您可以使用它来减少UIPopoverController内部计算中使用的屏幕区域,以确定弹出窗口的显示位置.

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];
Run Code Online (Sandbox Code Playgroud)

我认为通过调整上述内容,您将能够获得理想的结果.